Commit 280e1410ba0fb353dd666d2584c57047b0fdbec9
1 parent
7a4c13c468
Exists in
master
and in
1 other branch
agrego modal
Showing
1 changed file
with
8 additions
and
6 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 | 7 | ||
7 | @Component({ | 8 | @Component({ |
8 | templateUrl: './comprobantes.component.html', | 9 | templateUrl: './comprobantes.component.html', |
9 | styleUrls: ['./comprobantes.component.scss'], | 10 | styleUrls: ['./comprobantes.component.scss'], |
10 | providers:[ ComprobanteService ] | 11 | providers:[ ComprobanteService ] |
11 | }) | 12 | }) |
12 | export class ComprobantesComponent implements OnInit { | 13 | export class ComprobantesComponent implements OnInit { |
13 | 14 | ||
14 | constructor( | 15 | constructor( |
15 | private modalService: NgbModal, | 16 | private modalService: NgbModal, |
16 | public comprobanteService: ComprobanteService, | 17 | public comprobanteService: ComprobanteService, |
17 | public router: Router) { } | 18 | public router: Router, |
19 | private modal: ModalService) { } | ||
18 | 20 | ||
19 | ngOnInit() { } | 21 | ngOnInit() { } |
20 | 22 | ||
21 | filter = ''; | 23 | filter = ''; |
22 | estadoArticulos : string; | 24 | estadoArticulos : string; |
23 | tempRecibido = []; | 25 | tempRecibido = []; |
24 | cabecera = {}; | 26 | cabecera = {}; |
25 | cuerpo = []; | 27 | cuerpo = []; |
26 | articulosFiltro = []; | 28 | articulosFiltro = []; |
27 | saveLoading = false; | 29 | saveLoading = false; |
28 | showCabecera = true; | 30 | showCabecera = true; |
29 | 31 | ||
30 | fecha = new Date(); | 32 | fecha = new Date(); |
31 | 33 | ||
32 | getPaginaFiltro() { | 34 | getPaginaFiltro() { |
33 | 35 | ||
34 | this.articulosFiltro = this.cuerpo.filter((articulo) => { | 36 | this.articulosFiltro = this.cuerpo.filter((articulo) => { |
35 | 37 | ||
36 | var tio = articulo.TIO.trim().toLocaleUpperCase().includes(this.filter.toLocaleUpperCase()); | 38 | var tio = articulo.TIO.trim().toLocaleUpperCase().includes(this.filter.toLocaleUpperCase()); |
37 | var lio = articulo.LI0.trim().toLocaleUpperCase().includes(this.filter.toLocaleUpperCase()); | 39 | var lio = articulo.LI0.trim().toLocaleUpperCase().includes(this.filter.toLocaleUpperCase()); |
38 | var codigoBarras = articulo.codigoBarras == this.filter; | 40 | var codigoBarras = articulo.codigoBarras == this.filter; |
39 | 41 | ||
40 | articulo.cantidadRecibida != articulo.CAN && !articulo.estado ? articulo.estado = 'modificado' : | 42 | articulo.cantidadRecibida != articulo.CAN && !articulo.estado ? articulo.estado = 'modificado' : |
41 | false; | 43 | false; |
42 | 44 | ||
43 | var estado = articulo.estado == this.estadoArticulos; | 45 | var estado = articulo.estado == this.estadoArticulos; |
44 | 46 | ||
45 | return (tio || lio || codigoBarras) && estado; | 47 | return (tio || lio || codigoBarras) && estado; |
46 | }); | 48 | }); |
47 | 49 | ||
48 | return this.articulosFiltro; | 50 | return this.articulosFiltro; |
49 | } | 51 | } |
50 | 52 | ||
51 | getCantidadArticulosByEstado(estado: String) { | 53 | getCantidadArticulosByEstado(estado: String) { |
52 | return this.cuerpo.filter((articulo) => { | 54 | return this.cuerpo.filter((articulo) => { |
53 | return articulo.estado == estado; | 55 | return articulo.estado == estado; |
54 | }).length; | 56 | }).length; |
55 | } | 57 | } |
56 | 58 | ||
57 | guardarComprobante() { | 59 | guardarComprobante() { |
58 | 60 | ||
59 | if (this.getCantidadArticulosByEstado('pendiente')) { | 61 | if (this.getCantidadArticulosByEstado('pendiente')) { |
60 | alert('No deben quedar articulos pendientes'); | 62 | this.modal.alert('No deben quedar articulos pendientes'); |
61 | return; | 63 | return; |
62 | } | 64 | } |
63 | 65 | ||
64 | if (!this.cuerpo.length) { | 66 | if (!this.cuerpo.length) { |
65 | alert('Debe seleccionar un comprobante'); | 67 | this.modal.alert('Debe seleccionar un comprobante'); |
66 | return; | 68 | return; |
67 | } | 69 | } |
68 | 70 | ||
69 | this.saveLoading = true; | 71 | this.saveLoading = true; |
70 | 72 | ||
71 | this.comprobanteService | 73 | this.comprobanteService |
72 | .saveComprobantes({cabecera: this.cabecera, cuerpo: this.cuerpo}) | 74 | .saveComprobantes({cabecera: this.cabecera, cuerpo: this.cuerpo}) |
73 | .subscribe(data => { | 75 | .subscribe(data => { |
74 | 76 | ||
75 | alert('Comprobante guardado con éxito'); | 77 | this.modal.alert('Comprobante guardado con éxito'); |
76 | this.saveLoading = false; | 78 | this.saveLoading = false; |
77 | this.router.navigateByUrl('/home'); | 79 | this.router.navigateByUrl('/home'); |
78 | 80 | ||
79 | }, err => { | 81 | }, err => { |
80 | 82 | ||
81 | alert('Algo salió mal...'); | 83 | this.modal.alert('Algo salió mal...'); |
82 | this.saveLoading = false; | 84 | this.saveLoading = false; |
83 | console.log(err); | 85 | console.log(err); |
84 | }); | 86 | }); |
85 | } | 87 | } |
86 | 88 | ||
87 | busquedaComprobantes() { | 89 | busquedaComprobantes() { |
88 | this.modalService.open(BusquedaComprobanteComponent).result.then(comprobante => { | 90 | this.modalService.open(BusquedaComprobanteComponent).result.then(comprobante => { |
89 | 91 | ||
90 | this.cabecera = comprobante.cabecera; | 92 | this.cabecera = comprobante.cabecera; |
91 | 93 | ||
92 | comprobante.cuerpo.forEach(articulo => { | 94 | comprobante.cuerpo.forEach(articulo => { |
93 | articulo.cantidadRecibida = articulo.CAN; | 95 | articulo.cantidadRecibida = articulo.CAN; |
94 | }); | 96 | }); |
95 | 97 | ||
96 | this.cuerpo = comprobante.cuerpo; | 98 | this.cuerpo = comprobante.cuerpo; |
97 | 99 | ||
98 | this.getPaginaFiltro(); | 100 | this.getPaginaFiltro(); |
99 | }, (reason) => { }); | 101 | }, (reason) => { }); |
100 | } | 102 | } |
101 | 103 | ||
102 | inputArticulo(articulo) { | 104 | inputArticulo(articulo) { |
103 | if (articulo.tempRecibido > 999999) { | 105 | if (articulo.tempRecibido > 999999) { |
104 | alert('Cantidad máxima superada'); | 106 | this.modal.alert('Cantidad máxima superada'); |
105 | return; | 107 | return; |
106 | } | 108 | } |
107 | articulo.input = false; | 109 | articulo.input = false; |
108 | articulo.cantidadRecibida = articulo.tempRecibido || articulo.CAN; | 110 | articulo.cantidadRecibida = articulo.tempRecibido || articulo.CAN; |
109 | } | 111 | } |
110 | 112 | ||
111 | } | 113 | } |
112 | 114 |