Commit 269677a9aa3de539bbd350588f80be75d8a3af14
1 parent
3860f1b8db
Exists in
master
controlo cuando el comprobante existe
Showing
2 changed files
with
19 additions
and
5 deletions
Show diff stats
src/app/comprobantes/comprobantes.component.ts
| 1 | import { Component, OnInit} from '@angular/core'; | 1 | import { Component, OnInit} from '@angular/core'; |
| 2 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; | 2 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; |
| 3 | import { BusquedaComprobanteComponent } from '../busqueda-comprobante/busqueda-comprobante.component'; | 3 | import { BusquedaComprobanteComponent } from '../busqueda-comprobante/busqueda-comprobante.component'; |
| 4 | import { ComprobanteService } from './comprobantes.service'; | 4 | import { ComprobanteService } from './comprobantes.service'; |
| 5 | import { Router } from '@angular/router'; | 5 | import { Router } from '@angular/router'; |
| 6 | import { ModalService } from '../modal/modal.service'; | 6 | import { ModalService } from '../modal/modal.service'; |
| 7 | 7 | ||
| 8 | @Component({ | 8 | @Component({ |
| 9 | templateUrl: './comprobantes.component.html', | 9 | templateUrl: './comprobantes.component.html', |
| 10 | styleUrls: ['./comprobantes.component.scss'], | 10 | styleUrls: ['./comprobantes.component.scss'], |
| 11 | providers: [ ComprobanteService ] | 11 | providers: [ ComprobanteService ] |
| 12 | }) | 12 | }) |
| 13 | export class ComprobantesComponent implements OnInit { | 13 | export class ComprobantesComponent implements OnInit { |
| 14 | 14 | ||
| 15 | constructor( | 15 | constructor( |
| 16 | private modalService: NgbModal, | 16 | private modalService: NgbModal, |
| 17 | public comprobanteService: ComprobanteService, | 17 | public comprobanteService: ComprobanteService, |
| 18 | public router: Router, | 18 | public router: Router, |
| 19 | private modal: ModalService) { } | 19 | private modal: ModalService) { } |
| 20 | 20 | ||
| 21 | ngOnInit() { } | 21 | ngOnInit() { } |
| 22 | 22 | ||
| 23 | filter = ''; | 23 | filter = ''; |
| 24 | estadoArticulos : string; | 24 | estadoArticulos : string; |
| 25 | tempRecibido = []; | 25 | tempRecibido = []; |
| 26 | cabecera = {}; | 26 | cabecera = {}; |
| 27 | cuerpo = []; | 27 | cuerpo = []; |
| 28 | articulosFiltro = []; | 28 | articulosFiltro = []; |
| 29 | saveLoading = false; | 29 | saveLoading = false; |
| 30 | showCabecera = true; | 30 | showCabecera = true; |
| 31 | 31 | ||
| 32 | fecha = new Date(); | 32 | fecha = new Date(); |
| 33 | 33 | ||
| 34 | getPaginaFiltro() { | 34 | getPaginaFiltro() { |
| 35 | 35 | ||
| 36 | this.articulosFiltro = this.cuerpo.filter((articulo) => { | 36 | this.articulosFiltro = this.cuerpo.filter((articulo) => { |
| 37 | 37 | ||
| 38 | var tio = articulo.TIO.trim().toLocaleUpperCase().includes(this.filter.toLocaleUpperCase()); | 38 | var tio = articulo.TIO.trim().toLocaleUpperCase().includes(this.filter.toLocaleUpperCase()); |
| 39 | var lio = articulo.LI0.trim().toLocaleUpperCase().includes(this.filter.toLocaleUpperCase()); | 39 | var lio = articulo.LI0.trim().toLocaleUpperCase().includes(this.filter.toLocaleUpperCase()); |
| 40 | var codigoBarras = articulo.codigoBarras == this.filter; | 40 | var codigoBarras = articulo.codigoBarras == this.filter; |
| 41 | 41 | ||
| 42 | articulo.cantidadRecibida != articulo.CAN && !articulo.estado ? articulo.estado = 'modificado' : | 42 | articulo.cantidadRecibida != articulo.CAN && !articulo.estado ? articulo.estado = 'modificado' : |
| 43 | false; | 43 | false; |
| 44 | 44 | ||
| 45 | var estado = articulo.estado == this.estadoArticulos; | 45 | var estado = articulo.estado == this.estadoArticulos; |
| 46 | 46 | ||
| 47 | return (tio || lio || codigoBarras) && estado; | 47 | return (tio || lio || codigoBarras) && estado; |
| 48 | }); | 48 | }); |
| 49 | 49 | ||
| 50 | return this.articulosFiltro; | 50 | return this.articulosFiltro; |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | getCantidadArticulosByEstado(estado: String) { | 53 | getCantidadArticulosByEstado(estado: String) { |
| 54 | return this.cuerpo.filter((articulo) => { | 54 | return this.cuerpo.filter((articulo) => { |
| 55 | return articulo.estado == estado; | 55 | return articulo.estado == estado; |
| 56 | }).length; | 56 | }).length; |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | guardarComprobante() { | 59 | guardarComprobante() { |
| 60 | 60 | ||
| 61 | if (this.getCantidadArticulosByEstado('pendiente')) { | 61 | if (this.getCantidadArticulosByEstado('pendiente')) { |
| 62 | this.modal.alert('No deben quedar articulos pendientes'); | 62 | this.modal.alert('No deben quedar articulos pendientes'); |
| 63 | return; | 63 | return; |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | if (!this.cuerpo.length) { | 66 | if (!this.cuerpo.length) { |
| 67 | this.modal.alert('Debe seleccionar un comprobante'); | 67 | this.modal.alert('Debe seleccionar un comprobante'); |
| 68 | return; | 68 | return; |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | this.saveLoading = true; | 71 | this.saveLoading = true; |
| 72 | 72 | ||
| 73 | this.comprobanteService | 73 | this.comprobanteService |
| 74 | .saveComprobantes({cabecera: this.cabecera, cuerpo: this.cuerpo}) | 74 | .saveComprobantes({cabecera: this.cabecera, cuerpo: this.cuerpo}) |
| 75 | .subscribe(data => { | 75 | .subscribe(data => { |
| 76 | 76 | ||
| 77 | this.modal.alert('Comprobante guardado con éxito'); | 77 | this.modal.alert('Comprobante guardado con éxito').result.then( () => { |
| 78 | this.saveLoading = false; | 78 | |
| 79 | this.router.navigateByUrl('/home'); | 79 | this.saveLoading = false; |
| 80 | this.router.navigateByUrl('/home'); | ||
| 81 | }); | ||
| 80 | 82 | ||
| 81 | }, err => { | 83 | }, err => { |
| 82 | 84 | ||
| 83 | this.modal.alert('Algo salió mal...'); | 85 | if (err.status == 510) { |
| 86 | |||
| 87 | this.modal.alert('Ya existe el comprobante').result.then(() => { | ||
| 88 | |||
| 89 | this.router.navigateByUrl('/home'); | ||
| 90 | }); | ||
| 91 | } else { | ||
| 92 | |||
| 93 | this.modal.alert('Algo salió mal...'); | ||
| 94 | } | ||
| 95 | |||
| 84 | this.saveLoading = false; | 96 | this.saveLoading = false; |
| 85 | console.log(err); | 97 | console.log(err); |
| 86 | }); | 98 | }); |
| 87 | } | 99 | } |
| 88 | 100 | ||
| 89 | busquedaComprobantes() { | 101 | busquedaComprobantes() { |
| 90 | this.modalService.open(BusquedaComprobanteComponent).result.then(comprobante => { | 102 | this.modalService.open(BusquedaComprobanteComponent).result.then(comprobante => { |
| 91 | 103 | ||
| 92 | this.cabecera = comprobante.cabecera; | 104 | this.cabecera = comprobante.cabecera; |
| 93 | 105 | ||
| 94 | comprobante.cuerpo.forEach(articulo => { | 106 | comprobante.cuerpo.forEach(articulo => { |
| 95 | articulo.cantidadRecibida = articulo.CAN; | 107 | articulo.cantidadRecibida = articulo.CAN; |
| 96 | }); | 108 | }); |
| 97 | 109 | ||
| 98 | this.cuerpo = comprobante.cuerpo; | 110 | this.cuerpo = comprobante.cuerpo; |
| 99 | 111 | ||
| 100 | this.getPaginaFiltro(); | 112 | this.getPaginaFiltro(); |
| 101 | }, (reason) => { }); | 113 | }, (reason) => { }); |
| 102 | } | 114 | } |
| 103 | 115 | ||
| 104 | inputArticulo(articulo) { | 116 | inputArticulo(articulo) { |
| 105 | if (articulo.tempRecibido > 999999) { | 117 | if (articulo.tempRecibido > 999999) { |
| 106 | this.modal.alert('Cantidad máxima superada'); | 118 | this.modal.alert('Cantidad máxima superada'); |
| 107 | return; | 119 | return; |
| 108 | } | 120 | } |
| 109 | articulo.input = false; | 121 | articulo.input = false; |
| 110 | articulo.cantidadRecibida = articulo.tempRecibido || articulo.CAN; | 122 | articulo.cantidadRecibida = articulo.tempRecibido || articulo.CAN; |
| 111 | } | 123 | } |
| 112 | 124 | ||
| 113 | } | 125 | } |
| 114 | 126 |
src/app/modal/modal.service.ts
| 1 | import { Injectable, ViewChild } from '@angular/core'; | 1 | import { Injectable, ViewChild } from '@angular/core'; |
| 2 | import { NgbModal, NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; | 2 | import { NgbModal, NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; |
| 3 | import { ModalAlertComponent } from './modal-alert/modal-alert.component'; | 3 | import { ModalAlertComponent } from './modal-alert/modal-alert.component'; |
| 4 | 4 | ||
| 5 | @Injectable({ | 5 | @Injectable({ |
| 6 | providedIn: 'root' | 6 | providedIn: 'root' |
| 7 | }) | 7 | }) |
| 8 | export class ModalService { | 8 | export class ModalService { |
| 9 | 9 | ||
| 10 | constructor(private modalService: NgbModal) { } | 10 | constructor(private modalService: NgbModal) { } |
| 11 | 11 | ||
| 12 | modalComponent: ModalAlertComponent; | 12 | modalComponent: ModalAlertComponent; |
| 13 | 13 | ||
| 14 | alert(texto: string) { | 14 | alert(texto: string) { |
| 15 | return this.modalService.open(ModalAlertComponent).componentInstance.textoModal = texto; | 15 | let modal = this.modalService.open(ModalAlertComponent) |
| 16 | modal.componentInstance.textoModal = texto; | ||
| 17 | return modal; | ||
| 16 | } | 18 | } |
| 17 | } | 19 | } |
| 18 | 20 |