Commit 96fc7b3af628331af667e7277d98961d22f3634d
Exists in
master
and in
1 other branch
Merge branch 'master' into 'develop'
Master(mpuebla) See merge request !126
Showing
15 changed files
Show diff stats
src/app/components/busqueda-productos/busqueda-productos.component.ts
1 | import { Component, OnInit, EventEmitter } from '@angular/core'; | 1 | import { Component, OnInit, EventEmitter } from '@angular/core'; |
2 | import { ProductoService } from 'src/app/services/producto.service'; | 2 | import { ProductoService } from 'src/app/services/producto.service'; |
3 | import { Producto } from 'src/app/wrappers/producto'; | 3 | import { Producto } from 'src/app/wrappers/producto'; |
4 | import { Categoria } from 'src/app/wrappers/categoria'; | 4 | import { Categoria } from 'src/app/wrappers/categoria'; |
5 | import { appSettings } from 'src/etc/AppSettings'; | 5 | import { APP_SETTINGS } from 'src/etc/AppSettings'; |
6 | import { Router } from '@angular/router'; | 6 | import { Router } from '@angular/router'; |
7 | 7 | ||
8 | @Component({ | 8 | @Component({ |
9 | selector: 'app-busqueda-productos', | 9 | selector: 'app-busqueda-productos', |
10 | templateUrl: './busqueda-productos.component.html', | 10 | templateUrl: './busqueda-productos.component.html', |
11 | styleUrls: ['./busqueda-productos.component.scss'] | 11 | styleUrls: ['./busqueda-productos.component.scss'] |
12 | }) | 12 | }) |
13 | export class BusquedaProductosComponent implements OnInit { | 13 | export class BusquedaProductosComponent implements OnInit { |
14 | 14 | ||
15 | private productos: Producto[] = []; | 15 | private productos: Producto[] = []; |
16 | private auxProductos: Producto[] = []; | 16 | private auxProductos: Producto[] = []; |
17 | private searchTerm: string = ''; | 17 | private searchTerm: string = ''; |
18 | private categoriaActive: number = null; | 18 | private categoriaActive: number = null; |
19 | private showSpinner: boolean = true; | 19 | private showSpinner: boolean = true; |
20 | private queMostrar: string = 'todos'; | 20 | private queMostrar: string = 'todos'; |
21 | private apiImagenes: string = appSettings.apiImagenes; | 21 | private apiImagenes: string = APP_SETTINGS.apiImagenes; |
22 | private categorias: Categoria[] = []; | 22 | private categorias: Categoria[] = []; |
23 | private blurFocus = new EventEmitter(); | 23 | private blurFocus = new EventEmitter(); |
24 | private ordenandoByVendidos = true; | 24 | private ordenandoByVendidos = true; |
25 | private title: string = 'Búsqueda' | 25 | private title: string = 'Búsqueda' |
26 | 26 | ||
27 | constructor( | 27 | constructor( |
28 | private productoService: ProductoService, | 28 | private productoService: ProductoService, |
29 | private router: Router) { } | 29 | private router: Router) { } |
30 | 30 | ||
31 | ngOnInit() { | 31 | ngOnInit() { |
32 | 32 | ||
33 | this.queMostrar = this.productoService.mostrar; | 33 | this.queMostrar = this.productoService.mostrar; |
34 | 34 | ||
35 | this.productoService.getCategorias() | 35 | this.productoService.getCategorias() |
36 | .subscribe((categorias: Categoria[]) => { | 36 | .subscribe((categorias: Categoria[]) => { |
37 | 37 | ||
38 | switch (this.queMostrar) { | 38 | switch (this.queMostrar) { |
39 | case 'todos': | 39 | case 'todos': |
40 | this.categorias = categorias; | 40 | this.categorias = categorias; |
41 | this.categoriaActive = 0; | 41 | this.categoriaActive = 0; |
42 | this.title = 'Búsqueda'; | 42 | this.title = 'Búsqueda'; |
43 | break; | 43 | break; |
44 | case 'promociones': | 44 | case 'promociones': |
45 | this.categorias = categorias; | 45 | this.categorias = categorias; |
46 | this.categoriaActive = 1; | 46 | this.categoriaActive = 1; |
47 | this.title = 'Promociones'; | 47 | this.title = 'Promociones'; |
48 | break; | 48 | break; |
49 | case 'ordenar': | 49 | case 'ordenar': |
50 | this.categorias = categorias.filter((categoria: Categoria) => { | 50 | this.categorias = categorias.filter((categoria: Categoria) => { |
51 | return categoria.ES_PEDIDO; | 51 | return categoria.ES_PEDIDO; |
52 | }); | 52 | }); |
53 | this.categoriaActive = 0; | 53 | this.categoriaActive = 0; |
54 | this.title = 'Ordenar'; | 54 | this.title = 'Ordenar'; |
55 | break; | 55 | break; |
56 | default: | 56 | default: |
57 | this.categorias = categorias; | 57 | this.categorias = categorias; |
58 | this.categoriaActive = 0; | 58 | this.categoriaActive = 0; |
59 | this.title = 'Búsqueda'; | 59 | this.title = 'Búsqueda'; |
60 | break; | 60 | break; |
61 | } | 61 | } |
62 | }); | 62 | }); |
63 | 63 | ||
64 | this.productoService.productoAcargar = undefined; | 64 | this.productoService.productoAcargar = undefined; |
65 | this.productoService.getAll() | 65 | this.productoService.getAll() |
66 | .subscribe((data: Producto[]) => { | 66 | .subscribe((data: Producto[]) => { |
67 | 67 | ||
68 | this.setProductosSinImagen(data); | 68 | this.setProductosSinImagen(data); |
69 | 69 | ||
70 | if (this.queMostrar == 'ordenar') { | 70 | if (this.queMostrar == 'ordenar') { |
71 | 71 | ||
72 | this.categorias.forEach((categoria: Categoria) => { | 72 | this.categorias.forEach((categoria: Categoria) => { |
73 | 73 | ||
74 | let tempProductos = data.filter((producto: Producto) => { | 74 | let tempProductos = data.filter((producto: Producto) => { |
75 | return producto.categoria_selfservice == categoria.id; | 75 | return producto.categoria_selfservice == categoria.id; |
76 | }); | 76 | }); |
77 | 77 | ||
78 | this.productos = this.productos.concat(tempProductos); | 78 | this.productos = this.productos.concat(tempProductos); |
79 | 79 | ||
80 | }); | 80 | }); |
81 | } else { | 81 | } else { |
82 | this.productos = data; | 82 | this.productos = data; |
83 | } | 83 | } |
84 | this.filterItems(); | 84 | this.filterItems(); |
85 | }, (error) => { | 85 | }, (error) => { |
86 | this.showSpinner = false; | 86 | this.showSpinner = false; |
87 | console.error(error); | 87 | console.error(error); |
88 | }); | 88 | }); |
89 | } | 89 | } |
90 | 90 | ||
91 | filterItems() { | 91 | filterItems() { |
92 | 92 | ||
93 | this.auxProductos = this.productos.filter(x => { | 93 | this.auxProductos = this.productos.filter(x => { |
94 | if (this.categoriaActive === 0) { | 94 | if (this.categoriaActive === 0) { |
95 | return x.DET_LAR.toLowerCase().includes(this.searchTerm.toLowerCase()); | 95 | return x.DET_LAR.toLowerCase().includes(this.searchTerm.toLowerCase()); |
96 | } | 96 | } |
97 | else { | 97 | else { |
98 | return x.DET_LAR.toLowerCase().includes(this.searchTerm.toLowerCase()) && | 98 | return x.DET_LAR.toLowerCase().includes(this.searchTerm.toLowerCase()) && |
99 | x.categoria_selfservice === this.categoriaActive; | 99 | x.categoria_selfservice === this.categoriaActive; |
100 | } | 100 | } |
101 | }); | 101 | }); |
102 | 102 | ||
103 | this.ordenar(); | 103 | this.ordenar(); |
104 | 104 | ||
105 | } | 105 | } |
106 | 106 | ||
107 | agregarAlCarrito(producto: Producto) { | 107 | agregarAlCarrito(producto: Producto) { |
108 | 108 | ||
109 | producto.cantidad = 1; | 109 | producto.cantidad = 1; |
110 | this.productoService.productos.push(producto); | 110 | this.productoService.productos.push(producto); |
111 | } | 111 | } |
112 | 112 | ||
113 | ordenar() { | 113 | ordenar() { |
114 | 114 | ||
115 | if (this.ordenandoByVendidos) { | 115 | if (this.ordenandoByVendidos) { |
116 | 116 | ||
117 | this.auxProductos.sort((a, b) => { | 117 | this.auxProductos.sort((a, b) => { |
118 | return b.cantidadVendida - a.cantidadVendida; | 118 | return b.cantidadVendida - a.cantidadVendida; |
119 | }); | 119 | }); |
120 | } | 120 | } |
121 | 121 | ||
122 | } | 122 | } |
123 | 123 | ||
124 | private elegirProducto(producto: Producto) { | 124 | private elegirProducto(producto: Producto) { |
125 | 125 | ||
126 | if (producto.PRO) { | 126 | if (producto.PRO) { |
127 | 127 | ||
128 | let imagenes = producto.imagenes; | 128 | let imagenes = producto.imagenes; |
129 | this.productoService.getPromocionByCodigos(producto.CodSec, producto.CodArt) | 129 | this.productoService.getPromocionByCodigos(producto.CodSec, producto.CodArt) |
130 | .subscribe(res => { | 130 | .subscribe(res => { |
131 | 131 | ||
132 | this.productoService.productoAcargar = res[0]; | 132 | this.productoService.productoAcargar = res[0]; |
133 | this.productoService.productoAcargar.imagenes = imagenes; | 133 | this.productoService.productoAcargar.imagenes = imagenes; |
134 | this.router.navigate(['inicio']); | 134 | this.router.navigate(['inicio']); |
135 | }, | 135 | }, |
136 | error => { console.error(error); } | 136 | error => { console.error(error); } |
137 | ); | 137 | ); |
138 | } else { | 138 | } else { |
139 | 139 | ||
140 | this.productoService.productoAcargar = producto; | 140 | this.productoService.productoAcargar = producto; |
141 | this.router.navigate(['inicio']); | 141 | this.router.navigate(['inicio']); |
142 | } | 142 | } |
143 | 143 | ||
144 | } | 144 | } |
145 | 145 | ||
146 | private setProductosSinImagen(productos: Producto[]) { | 146 | private setProductosSinImagen(productos: Producto[]) { |
147 | 147 | ||
148 | productos.forEach((producto: Producto) => { | 148 | productos.forEach((producto: Producto) => { |
149 | producto.imagenes = producto.imagenes.length == 0 ? | 149 | producto.imagenes = producto.imagenes.length == 0 ? |
150 | [{ imagen: 'noImage.jpg' }] : producto.imagenes; | 150 | [{ imagen: 'noImage.jpg' }] : producto.imagenes; |
151 | }) | 151 | }) |
152 | } | 152 | } |
153 | } | 153 | } |
154 | 154 |
src/app/components/cancelar-compra/cancelar-compra.component.ts
1 | import { Component, OnInit, OnDestroy } from '@angular/core'; | 1 | import { Component, OnInit, OnDestroy } from '@angular/core'; |
2 | import { appSettings } from 'src/etc/AppSettings'; | 2 | import { APP_SETTINGS } from 'src/etc/AppSettings'; |
3 | import { Location } from '@angular/common'; | 3 | import { Location } from '@angular/common'; |
4 | import { Router } from '@angular/router'; | 4 | import { Router } from '@angular/router'; |
5 | import { ProductoService } from 'src/app/services/producto.service'; | 5 | import { ProductoService } from 'src/app/services/producto.service'; |
6 | 6 | ||
7 | @Component({ | 7 | @Component({ |
8 | selector: 'app-cancelar-compra', | 8 | selector: 'app-cancelar-compra', |
9 | templateUrl: './cancelar-compra.component.html', | 9 | templateUrl: './cancelar-compra.component.html', |
10 | styleUrls: ['./cancelar-compra.component.scss'] | 10 | styleUrls: ['./cancelar-compra.component.scss'] |
11 | }) | 11 | }) |
12 | export class CancelarCompraComponent implements OnInit, OnDestroy { | 12 | export class CancelarCompraComponent implements OnInit, OnDestroy { |
13 | 13 | ||
14 | private apiImagenes: string = appSettings.apiImagenes; | 14 | private apiImagenes: string = APP_SETTINGS.apiImagenes; |
15 | private timer: any; | 15 | private timer: any; |
16 | 16 | ||
17 | constructor( | 17 | constructor( |
18 | private location: Location, | 18 | private location: Location, |
19 | private router: Router, | 19 | private router: Router, |
20 | private productoService: ProductoService | 20 | private productoService: ProductoService |
21 | ) { } | 21 | ) { } |
22 | 22 | ||
23 | ngOnInit() { | 23 | ngOnInit() { |
24 | 24 | ||
25 | this.timer = setTimeout(() => { | 25 | this.timer = setTimeout(() => { |
26 | this.limpiarCarritoYvolver(); | 26 | this.limpiarCarritoYvolver(); |
27 | }, 30000) | 27 | }, 30000) |
28 | } | 28 | } |
29 | 29 | ||
30 | ngOnDestroy() { | 30 | ngOnDestroy() { |
31 | 31 | ||
32 | clearTimeout(this.timer); | 32 | clearTimeout(this.timer); |
33 | } | 33 | } |
34 | 34 | ||
35 | volverPreviousPage() { | 35 | volverPreviousPage() { |
36 | 36 | ||
37 | this.location.back(); | 37 | this.location.back(); |
38 | } | 38 | } |
39 | 39 | ||
40 | limpiarCarritoYvolver() { | 40 | limpiarCarritoYvolver() { |
41 | 41 | ||
42 | this.productoService.productoAcargar = undefined; | 42 | this.productoService.productoAcargar = undefined; |
43 | this.productoService.promoAcargar = undefined; | 43 | this.productoService.promoAcargar = undefined; |
44 | this.productoService.productos = []; | 44 | this.productoService.productos = []; |
45 | this.router.navigate(['/home']); | 45 | this.router.navigate(['/home']); |
46 | } | 46 | } |
47 | 47 | ||
48 | } | 48 | } |
49 | 49 |
src/app/components/confirmacion-carrito/confirmacion-carrito.component.ts
1 | import { Component, OnInit, OnDestroy } from '@angular/core'; | 1 | import { Component, OnInit, OnDestroy } from '@angular/core'; |
2 | import { appSettings } from 'src/etc/AppSettings'; | 2 | import { APP_SETTINGS } from 'src/etc/AppSettings'; |
3 | import { Location } from '@angular/common'; | 3 | import { Location } from '@angular/common'; |
4 | import { ProductoService } from 'src/app/services/producto.service'; | 4 | import { ProductoService } from 'src/app/services/producto.service'; |
5 | import { Producto } from 'src/app/wrappers/producto'; | 5 | import { Producto } from 'src/app/wrappers/producto'; |
6 | import { Router } from '@angular/router'; | 6 | import { Router } from '@angular/router'; |
7 | import { Subscription } from 'rxjs'; | 7 | import { Subscription } from 'rxjs'; |
8 | import { BsModalService } from 'ngx-bootstrap'; | 8 | import { BsModalService } from 'ngx-bootstrap'; |
9 | import { PagoConTarjetaComponent } from '../pago-con-tarjeta/pago-con-tarjeta.component'; | 9 | import { PagoConTarjetaComponent } from '../pago-con-tarjeta/pago-con-tarjeta.component'; |
10 | 10 | ||
11 | @Component({ | 11 | @Component({ |
12 | selector: 'app-confirmacion-carrito', | 12 | selector: 'app-confirmacion-carrito', |
13 | templateUrl: './confirmacion-carrito.component.html', | 13 | templateUrl: './confirmacion-carrito.component.html', |
14 | styleUrls: ['./confirmacion-carrito.component.scss'] | 14 | styleUrls: ['./confirmacion-carrito.component.scss'] |
15 | }) | 15 | }) |
16 | export class ConfirmacionCarritoComponent implements OnInit, OnDestroy { | 16 | export class ConfirmacionCarritoComponent implements OnInit, OnDestroy { |
17 | 17 | ||
18 | private apiImagenes: string = appSettings.apiImagenes; | 18 | private apiImagenes: string = APP_SETTINGS.apiImagenes; |
19 | private compraConEfectivofinalizada: boolean = false; | 19 | private compraConEfectivofinalizada: boolean = false; |
20 | private compraConQRfinalizada: boolean = false; | 20 | private compraConQRfinalizada: boolean = false; |
21 | private productos: Producto[] = []; | 21 | private productos: Producto[] = []; |
22 | private total: number = 0; | 22 | private total: number = 0; |
23 | private timerReposo: any; | 23 | private timerReposo: any; |
24 | private verQR: boolean = false; | 24 | private verQR: boolean = false; |
25 | private subscribePago: Subscription; | 25 | private subscribePago: Subscription; |
26 | private pedidoAnombreDe: string = ''; | 26 | private pedidoAnombreDe: string = ''; |
27 | 27 | ||
28 | constructor( | 28 | constructor( |
29 | private location: Location, | 29 | private location: Location, |
30 | private productoService: ProductoService, | 30 | private productoService: ProductoService, |
31 | private router: Router, | 31 | private router: Router, |
32 | private modalService: BsModalService, | 32 | private modalService: BsModalService, |
33 | ) { } | 33 | ) { } |
34 | 34 | ||
35 | ngOnInit() { | 35 | ngOnInit() { |
36 | 36 | ||
37 | this.timerReposo = setTimeout(() => { | 37 | this.timerReposo = setTimeout(() => { |
38 | 38 | ||
39 | this.router.navigate(['cancelar-compra']); | 39 | this.router.navigate(['cancelar-compra']); |
40 | }, 90000) | 40 | }, 90000) |
41 | this.productos = this.productoService.productos; | 41 | this.productos = this.productoService.productos; |
42 | } | 42 | } |
43 | 43 | ||
44 | ngOnDestroy() { | 44 | ngOnDestroy() { |
45 | 45 | ||
46 | if (this.subscribePago !== undefined) { | 46 | if (this.subscribePago !== undefined) { |
47 | this.subscribePago.unsubscribe(); | 47 | this.subscribePago.unsubscribe(); |
48 | } | 48 | } |
49 | clearTimeout(this.timerReposo); | 49 | clearTimeout(this.timerReposo); |
50 | } | 50 | } |
51 | 51 | ||
52 | volverPreviousPage() { | 52 | volverPreviousPage() { |
53 | 53 | ||
54 | if (this.subscribePago !== undefined) { | 54 | if (this.subscribePago !== undefined) { |
55 | this.subscribePago.unsubscribe(); | 55 | this.subscribePago.unsubscribe(); |
56 | } | 56 | } |
57 | 57 | ||
58 | if (this.verQR) { | 58 | if (this.verQR) { |
59 | this.verQR = !this.verQR; | 59 | this.verQR = !this.verQR; |
60 | return; | 60 | return; |
61 | } | 61 | } |
62 | 62 | ||
63 | this.location.back(); | 63 | this.location.back(); |
64 | } | 64 | } |
65 | 65 | ||
66 | getTotal() { | 66 | getTotal() { |
67 | 67 | ||
68 | var subTotal = 0; | 68 | var subTotal = 0; |
69 | this.productos.forEach(producto => { | 69 | this.productos.forEach(producto => { |
70 | 70 | ||
71 | subTotal = subTotal + (producto.PreVen * producto.cantidad); | 71 | subTotal = subTotal + (producto.PreVen * producto.cantidad); |
72 | }); | 72 | }); |
73 | return this.total = subTotal; | 73 | return this.total = subTotal; |
74 | } | 74 | } |
75 | 75 | ||
76 | reiniciarTimer() { | 76 | reiniciarTimer() { |
77 | 77 | ||
78 | clearTimeout(this.timerReposo); | 78 | clearTimeout(this.timerReposo); |
79 | this.timerReposo = setTimeout(() => { | 79 | this.timerReposo = setTimeout(() => { |
80 | 80 | ||
81 | this.router.navigate(['cancelar-compra']); | 81 | this.router.navigate(['cancelar-compra']); |
82 | }, 90000) | 82 | }, 90000) |
83 | } | 83 | } |
84 | 84 | ||
85 | //#region METODOS PARA LA FORMA DE PAGO | 85 | //#region METODOS PARA LA FORMA DE PAGO |
86 | pagar(medioPago: number) { | 86 | pagar(medioPago: number) { |
87 | 87 | ||
88 | this.verQR = medioPago === 9 ? true : false; | 88 | this.verQR = medioPago === 9 ? true : false; |
89 | let dataPago = { | 89 | let dataPago = { |
90 | medioPago: medioPago, | 90 | medioPago: medioPago, |
91 | pedidoAnombreDe: this.pedidoAnombreDe | 91 | pedidoAnombreDe: this.pedidoAnombreDe |
92 | } | 92 | } |
93 | this.subscribePago = this.productoService.pagar(dataPago) | 93 | this.subscribePago = this.productoService.pagar(dataPago) |
94 | .subscribe((res: any) => { | 94 | .subscribe((res: any) => { |
95 | 95 | ||
96 | clearTimeout(this.timerReposo); | 96 | clearTimeout(this.timerReposo); |
97 | 97 | ||
98 | if (medioPago === 1) { | 98 | if (medioPago === 1) { |
99 | this.compraConEfectivofinalizada = true; | 99 | this.compraConEfectivofinalizada = true; |
100 | } else if (medioPago === 9) { | 100 | } else if (medioPago === 9) { |
101 | this.compraConQRfinalizada = true; | 101 | this.compraConQRfinalizada = true; |
102 | } | 102 | } |
103 | 103 | ||
104 | setTimeout(() => { | 104 | setTimeout(() => { |
105 | 105 | ||
106 | this.router.navigate(['mensaje-final']); | 106 | this.router.navigate(['mensaje-final']); |
107 | }, 10000); | 107 | }, 10000); |
108 | }, err => { | 108 | }, err => { |
109 | 109 | ||
110 | console.error(err); | 110 | console.error(err); |
111 | alert('Algo salió mal'); | 111 | alert('Algo salió mal'); |
112 | }) | 112 | }) |
113 | } | 113 | } |
114 | //#endregion | 114 | //#endregion |
115 | 115 | ||
116 | abrirPagoConTarjeta() { | 116 | abrirPagoConTarjeta() { |
117 | 117 | ||
118 | this.modalService.show(PagoConTarjetaComponent, { | 118 | this.modalService.show(PagoConTarjetaComponent, { |
119 | class: 'modal-lg', | 119 | class: 'modal-lg', |
120 | ignoreBackdropClick: true, | 120 | ignoreBackdropClick: true, |
121 | initialState: { importeTotal: this.total }, | 121 | initialState: { importeTotal: this.total }, |
122 | }); | 122 | }); |
123 | } | 123 | } |
124 | } | 124 | } |
125 | 125 |
src/app/components/header/header.component.ts
1 | import { Component, OnInit, HostListener } from '@angular/core'; | 1 | import { Component, OnInit, HostListener } from '@angular/core'; |
2 | import { appSettings } from 'src/etc/AppSettings'; | 2 | import { APP_SETTINGS } from 'src/etc/AppSettings'; |
3 | import { BsModalService } from 'ngx-bootstrap'; | 3 | import { BsModalService } from 'ngx-bootstrap'; |
4 | import { ConfiguracionComponent } from '../configuracion/configuracion.component'; | 4 | import { ConfiguracionComponent } from '../configuracion/configuracion.component'; |
5 | 5 | ||
6 | @Component({ | 6 | @Component({ |
7 | selector: 'app-header', | 7 | selector: 'app-header', |
8 | templateUrl: './header.component.html', | 8 | templateUrl: './header.component.html', |
9 | styleUrls: ['./header.component.scss'] | 9 | styleUrls: ['./header.component.scss'] |
10 | }) | 10 | }) |
11 | export class HeaderComponent implements OnInit { | 11 | export class HeaderComponent implements OnInit { |
12 | 12 | ||
13 | private apiImagenes : string = appSettings.apiImagenes; | 13 | private apiImagenes : string = APP_SETTINGS.apiImagenes; |
14 | timer: any; | 14 | timer: any; |
15 | isShowModalConfiguration = false; | 15 | isShowModalConfiguration = false; |
16 | 16 | ||
17 | constructor( | 17 | constructor( |
18 | private modalService: BsModalService, | 18 | private modalService: BsModalService, |
19 | ) { } | 19 | ) { } |
20 | 20 | ||
21 | ngOnInit() { | 21 | ngOnInit() { |
22 | } | 22 | } |
23 | 23 | ||
24 | @HostListener('document:keydown.Control.Shift.A', ['$event']) | 24 | @HostListener('document:keydown.Control.Shift.A', ['$event']) |
25 | openConfigurationScreen(delay: number = 3000) { | 25 | openConfigurationScreen(delay: number = 3000) { |
26 | 26 | ||
27 | if (this.isShowModalConfiguration) return; | 27 | if (this.isShowModalConfiguration) return; |
28 | 28 | ||
29 | this.modalService.onHide | 29 | this.modalService.onHide |
30 | .subscribe(() => this.isShowModalConfiguration = false); | 30 | .subscribe(() => this.isShowModalConfiguration = false); |
31 | 31 | ||
32 | this.timer = setTimeout(() => { | 32 | this.timer = setTimeout(() => { |
33 | 33 | ||
34 | this.isShowModalConfiguration = true; | 34 | this.isShowModalConfiguration = true; |
35 | this.modalService.show(ConfiguracionComponent, { | 35 | this.modalService.show(ConfiguracionComponent, { |
36 | class: 'modal-md', | 36 | class: 'modal-md', |
37 | ignoreBackdropClick: true, | 37 | ignoreBackdropClick: true, |
38 | }); | 38 | }); |
39 | }, delay); | 39 | }, delay); |
40 | } | 40 | } |
41 | 41 | ||
42 | resetCountDown() { | 42 | resetCountDown() { |
43 | 43 | ||
44 | clearTimeout(this.timer); | 44 | clearTimeout(this.timer); |
45 | } | 45 | } |
46 | 46 | ||
47 | } | 47 | } |
48 | 48 |
src/app/components/home/home.component.ts
1 | import { Component, OnInit, HostListener } from '@angular/core'; | 1 | import { Component, OnInit, HostListener } from '@angular/core'; |
2 | import { Router } from '@angular/router'; | 2 | import { Router } from '@angular/router'; |
3 | import { appSettings } from 'src/etc/AppSettings'; | 3 | import { APP_SETTINGS } from 'src/etc/AppSettings'; |
4 | 4 | ||
5 | @Component({ | 5 | @Component({ |
6 | selector: 'app-home', | 6 | selector: 'app-home', |
7 | templateUrl: './home.component.html', | 7 | templateUrl: './home.component.html', |
8 | styleUrls: ['./home.component.scss'] | 8 | styleUrls: ['./home.component.scss'] |
9 | }) | 9 | }) |
10 | export class HomeComponent implements OnInit { | 10 | export class HomeComponent implements OnInit { |
11 | 11 | ||
12 | private apiImagenes: string = appSettings.apiImagenes; | 12 | private apiImagenes: string = APP_SETTINGS.apiImagenes; |
13 | 13 | ||
14 | constructor() { } | 14 | constructor() { } |
15 | 15 | ||
16 | ngOnInit() { | 16 | ngOnInit() { |
17 | } | 17 | } |
18 | 18 | ||
19 | } | 19 | } |
20 | 20 |
src/app/components/inicio/inicio.component.ts
1 | import { Component, OnInit, ViewChild, HostListener, AfterViewInit } from '@angular/core'; | 1 | import { Component, OnInit, ViewChild, HostListener, AfterViewInit } from '@angular/core'; |
2 | import { PopoverDirective } from 'ngx-bootstrap'; | 2 | import { PopoverDirective } from 'ngx-bootstrap'; |
3 | import { appSettings } from 'src/etc/AppSettings'; | 3 | import { APP_SETTINGS } from 'src/etc/AppSettings'; |
4 | import { Router } from '@angular/router'; | 4 | import { Router } from '@angular/router'; |
5 | import { ProductoService } from 'src/app/services/producto.service'; | 5 | import { ProductoService } from 'src/app/services/producto.service'; |
6 | import { Producto } from 'src/app/wrappers/producto'; | 6 | import { Producto } from 'src/app/wrappers/producto'; |
7 | import { Sinonimo } from 'src/app/wrappers/sinonimo'; | 7 | import { Sinonimo } from 'src/app/wrappers/sinonimo'; |
8 | 8 | ||
9 | @Component({ | 9 | @Component({ |
10 | selector: 'app-inicio', | 10 | selector: 'app-inicio', |
11 | templateUrl: './inicio.component.html', | 11 | templateUrl: './inicio.component.html', |
12 | styleUrls: ['./inicio.component.scss'] | 12 | styleUrls: ['./inicio.component.scss'] |
13 | }) | 13 | }) |
14 | export class InicioComponent implements OnInit, AfterViewInit { | 14 | export class InicioComponent implements OnInit, AfterViewInit { |
15 | 15 | ||
16 | private tienePromo = false; | 16 | private tienePromo = false; |
17 | private productoEsPromo = false; | 17 | private productoEsPromo = false; |
18 | private busqueda: string = ''; | 18 | private busqueda: string = ''; |
19 | private productoAcargar: Producto; | 19 | private productoAcargar: Producto; |
20 | private promoAcargar: Producto; | 20 | private promoAcargar: Producto; |
21 | private productos: Producto[] = []; | 21 | private productos: Producto[] = []; |
22 | private promociones: Producto[] = []; | 22 | private promociones: Producto[] = []; |
23 | private sinonimos: Sinonimo[] = []; | 23 | private sinonimos: Sinonimo[] = []; |
24 | private apiImagenes: string = appSettings.apiImagenes; | 24 | private apiImagenes: string = APP_SETTINGS.apiImagenes; |
25 | 25 | ||
26 | @ViewChild('pop', { static: false }) popoverDirective: PopoverDirective; | 26 | @ViewChild('pop', { static: false }) popoverDirective: PopoverDirective; |
27 | 27 | ||
28 | @HostListener('document:keypress', ["$event"]) catchInput(e: KeyboardEvent) { | 28 | @HostListener('document:keypress', ["$event"]) catchInput(e: KeyboardEvent) { |
29 | 29 | ||
30 | if (e.keyCode == 13) { | 30 | if (e.keyCode == 13) { |
31 | this.buscarByCodigoBarras(this.busqueda); | 31 | this.buscarByCodigoBarras(this.busqueda); |
32 | this.busqueda = ''; | 32 | this.busqueda = ''; |
33 | } else { | 33 | } else { |
34 | this.busqueda += e.key; | 34 | this.busqueda += e.key; |
35 | } | 35 | } |
36 | }; | 36 | }; |
37 | 37 | ||
38 | constructor( | 38 | constructor( |
39 | private router: Router, | 39 | private router: Router, |
40 | private productoService: ProductoService | 40 | private productoService: ProductoService |
41 | ) { } | 41 | ) { } |
42 | 42 | ||
43 | ngOnInit() { | 43 | ngOnInit() { |
44 | 44 | ||
45 | this.productoAcargar = this.productoService.productoAcargar; | 45 | this.productoAcargar = this.productoService.productoAcargar; |
46 | this.getProductos(); | 46 | this.getProductos(); |
47 | } | 47 | } |
48 | 48 | ||
49 | ngAfterViewInit() { | 49 | ngAfterViewInit() { |
50 | 50 | ||
51 | setTimeout(() => { | 51 | setTimeout(() => { |
52 | if (!this.productoAcargar) return; | 52 | if (!this.productoAcargar) return; |
53 | 53 | ||
54 | if (this.productoAcargar.PRO) { | 54 | if (this.productoAcargar.PRO) { |
55 | this.promociones.push(this.productoAcargar); | 55 | this.promociones.push(this.productoAcargar); |
56 | this.promoSeleccionada(this.productoAcargar, true); | 56 | this.promoSeleccionada(this.productoAcargar, true); |
57 | } | 57 | } |
58 | else { | 58 | else { |
59 | this.getPromociones(); | 59 | this.getPromociones(); |
60 | } | 60 | } |
61 | }) | 61 | }) |
62 | } | 62 | } |
63 | 63 | ||
64 | getProductos() { | 64 | getProductos() { |
65 | 65 | ||
66 | this.productoService.getAll() | 66 | this.productoService.getAll() |
67 | .subscribe((productos: Producto[]) => { | 67 | .subscribe((productos: Producto[]) => { |
68 | this.productos = productos; | 68 | this.productos = productos; |
69 | }); | 69 | }); |
70 | } | 70 | } |
71 | 71 | ||
72 | getPromociones() { | 72 | getPromociones() { |
73 | 73 | ||
74 | var sector = this.productoAcargar.CodSec; | 74 | var sector = this.productoAcargar.CodSec; |
75 | var codigo = this.productoAcargar.CodArt; | 75 | var codigo = this.productoAcargar.CodArt; |
76 | this.productoService.getPromociones(sector, codigo) | 76 | this.productoService.getPromociones(sector, codigo) |
77 | .subscribe((res: Producto[]) => { | 77 | .subscribe((res: Producto[]) => { |
78 | 78 | ||
79 | if (res.length === 0) { | 79 | if (res.length === 0) { |
80 | 80 | ||
81 | this.productoAcargar.cantidad ? false : this.productoAcargar.cantidad = 1; | 81 | this.productoAcargar.cantidad ? false : this.productoAcargar.cantidad = 1; |
82 | this.productoService.setProductos(this.productoAcargar); | 82 | this.productoService.setProductos(this.productoAcargar); |
83 | this.productoAcargar = this.productoService.productoAcargar = undefined; | 83 | this.productoAcargar = this.productoService.productoAcargar = undefined; |
84 | } else { | 84 | } else { |
85 | 85 | ||
86 | this.promociones = res; | 86 | this.promociones = res; |
87 | this.popoverDirective.show(); | 87 | this.popoverDirective.show(); |
88 | } | 88 | } |
89 | }, error => { console.error(error); }) | 89 | }, error => { console.error(error); }) |
90 | } | 90 | } |
91 | 91 | ||
92 | confirmarProducto(cantidad?: number) { | 92 | confirmarProducto(cantidad?: number) { |
93 | 93 | ||
94 | let producto = this.promoAcargar ? this.promoAcargar : this.productoAcargar; | 94 | let producto = this.promoAcargar ? this.promoAcargar : this.productoAcargar; |
95 | 95 | ||
96 | if (cantidad) { | 96 | if (cantidad) { |
97 | producto.cantidad = cantidad; | 97 | producto.cantidad = cantidad; |
98 | } else { | 98 | } else { |
99 | producto.cantidad = producto.cantidad ? producto.cantidad : 1; | 99 | producto.cantidad = producto.cantidad ? producto.cantidad : 1; |
100 | } | 100 | } |
101 | 101 | ||
102 | this.productoService.setProductos(producto); | 102 | this.productoService.setProductos(producto); |
103 | this.productoService.productoAcargar = this.promoAcargar = this.productoAcargar = undefined; | 103 | this.productoService.productoAcargar = this.promoAcargar = this.productoAcargar = undefined; |
104 | this.productoService.esPromoPersonalizada = false; | 104 | this.productoService.esPromoPersonalizada = false; |
105 | this.promociones = []; | 105 | this.promociones = []; |
106 | this.popoverDirective.hide(); | 106 | this.popoverDirective.hide(); |
107 | } | 107 | } |
108 | 108 | ||
109 | promoSeleccionada($event: Producto, showPopover: boolean) { | 109 | promoSeleccionada($event: Producto, showPopover: boolean) { |
110 | 110 | ||
111 | this.productoService.getProductoById($event.id) | 111 | this.productoService.getProductoById($event.id) |
112 | .subscribe((res: Producto) => { | 112 | .subscribe((res: Producto) => { |
113 | 113 | ||
114 | $event.imagenes = res.imagenes.length == 0 ? [{ imagen: 'noImage.jpg' }] : res.imagenes; | 114 | $event.imagenes = res.imagenes.length == 0 ? [{ imagen: 'noImage.jpg' }] : res.imagenes; |
115 | this.promoAcargar = $event; | 115 | this.promoAcargar = $event; |
116 | 116 | ||
117 | if ($event.tieneSinonimos) { | 117 | if ($event.tieneSinonimos) { |
118 | this.getSinonimos(this.promoAcargar.CodSec, this.promoAcargar.CodArt); | 118 | this.getSinonimos(this.promoAcargar.CodSec, this.promoAcargar.CodArt); |
119 | } else if (showPopover) { | 119 | } else if (showPopover) { |
120 | this.popoverDirective.show(); | 120 | this.popoverDirective.show(); |
121 | } else { | 121 | } else { |
122 | this.popoverDirective.hide(); | 122 | this.popoverDirective.hide(); |
123 | } | 123 | } |
124 | 124 | ||
125 | }, | 125 | }, |
126 | error => { console.log(error); }) | 126 | error => { console.log(error); }) |
127 | } | 127 | } |
128 | 128 | ||
129 | getSinonimos(sector, codigo) { | 129 | getSinonimos(sector, codigo) { |
130 | 130 | ||
131 | this.productoService.getPromocionSinonimos(sector, codigo) | 131 | this.productoService.getPromocionSinonimos(sector, codigo) |
132 | .subscribe((res: Sinonimo[]) => { | 132 | .subscribe((res: Sinonimo[]) => { |
133 | 133 | ||
134 | res.forEach(sinonimo => { | 134 | res.forEach(sinonimo => { |
135 | 135 | ||
136 | sinonimo.cantidad = 0; | 136 | sinonimo.cantidad = 0; |
137 | this.promoAcargar.productos.forEach(productoPromo => { | 137 | this.promoAcargar.productos.forEach(productoPromo => { |
138 | 138 | ||
139 | sinonimo.productos.forEach(productoSinonimo => { | 139 | sinonimo.productos.forEach(productoSinonimo => { |
140 | 140 | ||
141 | if (productoSinonimo.id === productoPromo.id) { | 141 | if (productoSinonimo.id === productoPromo.id) { |
142 | productoSinonimo.cantidad = productoPromo.cantidad; | 142 | productoSinonimo.cantidad = productoPromo.cantidad; |
143 | sinonimo.cantidad += productoPromo.cantidad; | 143 | sinonimo.cantidad += productoPromo.cantidad; |
144 | } | 144 | } |
145 | }) | 145 | }) |
146 | }) | 146 | }) |
147 | }) | 147 | }) |
148 | this.sinonimos = res; | 148 | this.sinonimos = res; |
149 | (this.sinonimos.length > 0) ? this.popoverDirective.show() : this.popoverDirective.hide(); | 149 | (this.sinonimos.length > 0) ? this.popoverDirective.show() : this.popoverDirective.hide(); |
150 | }) | 150 | }) |
151 | } | 151 | } |
152 | 152 | ||
153 | productosPersonalizados($event: any) { | 153 | productosPersonalizados($event: any) { |
154 | 154 | ||
155 | let productosPersonalizados = $event.productosAenviar; | 155 | let productosPersonalizados = $event.productosAenviar; |
156 | 156 | ||
157 | productosPersonalizados.forEach(productoElegido => { | 157 | productosPersonalizados.forEach(productoElegido => { |
158 | 158 | ||
159 | this.promoAcargar.productos = this.promoAcargar.productos.filter(productoPromo => { | 159 | this.promoAcargar.productos = this.promoAcargar.productos.filter(productoPromo => { |
160 | return productoPromo.idSinonimo != productoElegido.idSinonimo; | 160 | return productoPromo.idSinonimo != productoElegido.idSinonimo; |
161 | }); | 161 | }); |
162 | }); | 162 | }); |
163 | 163 | ||
164 | this.promoAcargar.productos = this.promoAcargar.productos.concat(productosPersonalizados); | 164 | this.promoAcargar.productos = this.promoAcargar.productos.concat(productosPersonalizados); |
165 | this.confirmarProducto($event.cantidadPromo); | 165 | this.confirmarProducto($event.cantidadPromo); |
166 | } | 166 | } |
167 | 167 | ||
168 | buscarByCodigoBarras(busqueda) { | 168 | buscarByCodigoBarras(busqueda) { |
169 | 169 | ||
170 | let producto = this.productos.filter(producto => { | 170 | let producto = this.productos.filter(producto => { |
171 | return producto.codigoBarra == busqueda; | 171 | return producto.codigoBarra == busqueda; |
172 | }); | 172 | }); |
173 | 173 | ||
174 | if (producto.length) { | 174 | if (producto.length) { |
175 | 175 | ||
176 | this.productoAcargar = producto[0]; | 176 | this.productoAcargar = producto[0]; |
177 | this.getPromociones(); | 177 | this.getPromociones(); |
178 | 178 | ||
179 | } else { | 179 | } else { |
180 | alert('No se encuentra el producto'); | 180 | alert('No se encuentra el producto'); |
181 | } | 181 | } |
182 | 182 | ||
183 | } | 183 | } |
184 | 184 | ||
185 | irBusquedaProductos(value) { | 185 | irBusquedaProductos(value) { |
186 | 186 | ||
187 | this.productoService.mostrar = value; | 187 | this.productoService.mostrar = value; |
188 | this.router.navigate(['busqueda-productos']); | 188 | this.router.navigate(['busqueda-productos']); |
189 | } | 189 | } |
190 | 190 | ||
191 | deshacerCarga() { | 191 | deshacerCarga() { |
192 | 192 | ||
193 | if (this.sinonimos.length > 0) { | 193 | if (this.sinonimos.length > 0) { |
194 | this.sinonimos = []; | 194 | this.sinonimos = []; |
195 | this.productoService.esPromoPersonalizada = false; | 195 | this.productoService.esPromoPersonalizada = false; |
196 | this.popoverDirective.hide(); | 196 | this.popoverDirective.hide(); |
197 | } | 197 | } |
198 | 198 | ||
199 | if (this.promoAcargar) { | 199 | if (this.promoAcargar) { |
200 | this.promoAcargar = undefined; | 200 | this.promoAcargar = undefined; |
201 | if (this.productoAcargar.PRO) { | 201 | if (this.productoAcargar.PRO) { |
202 | this.productoAcargar = undefined; | 202 | this.productoAcargar = undefined; |
203 | this.promociones = []; | 203 | this.promociones = []; |
204 | this.popoverDirective.hide(); | 204 | this.popoverDirective.hide(); |
205 | } else { | 205 | } else { |
206 | this.popoverDirective.show(); | 206 | this.popoverDirective.show(); |
207 | } | 207 | } |
208 | } else { | 208 | } else { |
209 | this.productoAcargar = undefined; | 209 | this.productoAcargar = undefined; |
210 | this.promociones = []; | 210 | this.promociones = []; |
211 | this.popoverDirective.hide(); | 211 | this.popoverDirective.hide(); |
212 | } | 212 | } |
213 | } | 213 | } |
214 | 214 | ||
215 | } | 215 | } |
216 | 216 |
src/app/components/mensaje-final/mensaje-final.component.ts
1 | import { Component, OnInit } from '@angular/core'; | 1 | import { Component, OnInit } from '@angular/core'; |
2 | import { appSettings } from 'src/etc/AppSettings'; | 2 | import { APP_SETTINGS } from 'src/etc/AppSettings'; |
3 | import { ProductoService } from 'src/app/services/producto.service'; | 3 | import { ProductoService } from 'src/app/services/producto.service'; |
4 | import { Router } from '@angular/router'; | 4 | import { Router } from '@angular/router'; |
5 | 5 | ||
6 | @Component({ | 6 | @Component({ |
7 | selector: 'app-mensaje-final', | 7 | selector: 'app-mensaje-final', |
8 | templateUrl: './mensaje-final.component.html', | 8 | templateUrl: './mensaje-final.component.html', |
9 | styleUrls: ['./mensaje-final.component.scss'] | 9 | styleUrls: ['./mensaje-final.component.scss'] |
10 | }) | 10 | }) |
11 | export class MensajeFinalComponent implements OnInit { | 11 | export class MensajeFinalComponent implements OnInit { |
12 | 12 | ||
13 | private apiImagenes: string = appSettings.apiImagenes; | 13 | private apiImagenes: string = APP_SETTINGS.apiImagenes; |
14 | private timer: any; | 14 | private timer: any; |
15 | 15 | ||
16 | constructor( | 16 | constructor( |
17 | private productoService: ProductoService, | 17 | private productoService: ProductoService, |
18 | private router: Router | 18 | private router: Router |
19 | ) { } | 19 | ) { } |
20 | 20 | ||
21 | ngOnInit() { | 21 | ngOnInit() { |
22 | 22 | ||
23 | this.timer = setTimeout(() => { | 23 | this.timer = setTimeout(() => { |
24 | 24 | ||
25 | this.limpiarCarritoYvolver(); | 25 | this.limpiarCarritoYvolver(); |
26 | }, 3000) | 26 | }, 3000) |
27 | } | 27 | } |
28 | 28 | ||
29 | ngOnDestroy() { | 29 | ngOnDestroy() { |
30 | 30 | ||
31 | clearTimeout(this.timer); | 31 | clearTimeout(this.timer); |
32 | } | 32 | } |
33 | 33 | ||
34 | limpiarCarritoYvolver() { | 34 | limpiarCarritoYvolver() { |
35 | 35 | ||
36 | this.productoService.productoAcargar = undefined; | 36 | this.productoService.productoAcargar = undefined; |
37 | this.productoService.promoAcargar = undefined; | 37 | this.productoService.promoAcargar = undefined; |
38 | this.productoService.productos = []; | 38 | this.productoService.productos = []; |
39 | this.router.navigate(['/home']); | 39 | this.router.navigate(['/home']); |
40 | } | 40 | } |
41 | 41 | ||
42 | } | 42 | } |
43 | 43 |
src/app/components/sidebar/sidebar.component.ts
1 | import { Component, OnInit } from '@angular/core'; | 1 | import { Component, OnInit } from '@angular/core'; |
2 | import { Producto } from 'src/app/wrappers/producto'; | 2 | import { Producto } from 'src/app/wrappers/producto'; |
3 | import { appSettings } from 'src/etc/AppSettings'; | 3 | import { APP_SETTINGS } from 'src/etc/AppSettings'; |
4 | import { ProductoService } from 'src/app/services/producto.service'; | 4 | import { ProductoService } from 'src/app/services/producto.service'; |
5 | import { Router } from '@angular/router'; | 5 | import { Router } from '@angular/router'; |
6 | import { trigger, state, style, transition, animate } from '@angular/animations'; | 6 | import { trigger, state, style, transition, animate } from '@angular/animations'; |
7 | 7 | ||
8 | @Component({ | 8 | @Component({ |
9 | selector: 'app-sidebar', | 9 | selector: 'app-sidebar', |
10 | templateUrl: './sidebar.component.html', | 10 | templateUrl: './sidebar.component.html', |
11 | styleUrls: ['./sidebar.component.scss'], | 11 | styleUrls: ['./sidebar.component.scss'], |
12 | animations: [ | 12 | animations: [ |
13 | trigger('EnterLeave', [ | 13 | trigger('EnterLeave', [ |
14 | state('flyIn', style({ transform: 'translateX(0)' })), | 14 | state('flyIn', style({ transform: 'translateX(0)' })), |
15 | transition(':enter', [ | 15 | transition(':enter', [ |
16 | style({ transform: 'translateX(-100%)' }), | 16 | style({ transform: 'translateX(-100%)' }), |
17 | animate('0.3s ease-in') | 17 | animate('0.3s ease-in') |
18 | ]), | 18 | ]), |
19 | transition(':leave', [ | 19 | transition(':leave', [ |
20 | animate('0.3s ease-out', style({ transform: 'translateX(-100%)' })) | 20 | animate('0.3s ease-out', style({ transform: 'translateX(-100%)' })) |
21 | ]) | 21 | ]) |
22 | ]) | 22 | ]) |
23 | ] | 23 | ] |
24 | }) | 24 | }) |
25 | export class SidebarComponent implements OnInit { | 25 | export class SidebarComponent implements OnInit { |
26 | 26 | ||
27 | private cantTotal: number = 0; | 27 | private cantTotal: number = 0; |
28 | private cantMin: number = 1; | 28 | private cantMin: number = 1; |
29 | private cantMax: number = 50; | 29 | private cantMax: number = 50; |
30 | private total: number = 0; | 30 | private total: number = 0; |
31 | private apiImagenes: string = appSettings.apiImagenes; | 31 | private apiImagenes: string = APP_SETTINGS.apiImagenes; |
32 | 32 | ||
33 | public productosCarrito: Producto[] = []; | 33 | public productosCarrito: Producto[] = []; |
34 | 34 | ||
35 | constructor( | 35 | constructor( |
36 | private productoService: ProductoService, | 36 | private productoService: ProductoService, |
37 | private router: Router) { | 37 | private router: Router) { |
38 | this.router.routeReuseStrategy.shouldReuseRoute = function () { | 38 | this.router.routeReuseStrategy.shouldReuseRoute = function () { |
39 | return false; | 39 | return false; |
40 | } | 40 | } |
41 | } | 41 | } |
42 | 42 | ||
43 | ngOnInit() { | 43 | ngOnInit() { |
44 | 44 | ||
45 | this.productosCarrito = this.productoService.productos; | 45 | this.productosCarrito = this.productoService.productos; |
46 | } | 46 | } |
47 | 47 | ||
48 | getCantidadProductos() { | 48 | getCantidadProductos() { |
49 | 49 | ||
50 | var cantTotalAux = 0; | 50 | var cantTotalAux = 0; |
51 | this.productosCarrito.forEach(producto => { | 51 | this.productosCarrito.forEach(producto => { |
52 | 52 | ||
53 | cantTotalAux += producto.cantidad; | 53 | cantTotalAux += producto.cantidad; |
54 | }); | 54 | }); |
55 | this.cantTotal = cantTotalAux; | 55 | this.cantTotal = cantTotalAux; |
56 | 56 | ||
57 | return this.cantTotal; | 57 | return this.cantTotal; |
58 | } | 58 | } |
59 | 59 | ||
60 | getTotal() { | 60 | getTotal() { |
61 | 61 | ||
62 | var subTotal = 0; | 62 | var subTotal = 0; |
63 | for (let i = 0; i < this.productosCarrito.length; i++) { | 63 | for (let i = 0; i < this.productosCarrito.length; i++) { |
64 | subTotal = subTotal + (this.productosCarrito[i].PreVen * this.productosCarrito[i].cantidad); | 64 | subTotal = subTotal + (this.productosCarrito[i].PreVen * this.productosCarrito[i].cantidad); |
65 | } | 65 | } |
66 | return this.total = subTotal; | 66 | return this.total = subTotal; |
67 | } | 67 | } |
68 | 68 | ||
69 | aumentarCantidad(producto: Producto) { | 69 | aumentarCantidad(producto: Producto) { |
70 | 70 | ||
71 | if (producto.cantidad < this.cantMax) { | 71 | if (producto.cantidad < this.cantMax) { |
72 | producto.cantidad++; | 72 | producto.cantidad++; |
73 | this.cantTotal++ | 73 | this.cantTotal++ |
74 | } | 74 | } |
75 | } | 75 | } |
76 | 76 | ||
77 | restarCantidad(producto: Producto) { | 77 | restarCantidad(producto: Producto) { |
78 | 78 | ||
79 | if (producto.cantidad > this.cantMin) { | 79 | if (producto.cantidad > this.cantMin) { |
80 | producto.cantidad--; | 80 | producto.cantidad--; |
81 | this.cantTotal--; | 81 | this.cantTotal--; |
82 | } | 82 | } |
83 | } | 83 | } |
84 | 84 | ||
85 | deleteProducto(producto: Producto, index: number) { | 85 | deleteProducto(producto: Producto, index: number) { |
86 | 86 | ||
87 | this.cantTotal -= producto.cantidad; | 87 | this.cantTotal -= producto.cantidad; |
88 | this.total -= producto.PreVen * producto.cantidad; | 88 | this.total -= producto.PreVen * producto.cantidad; |
89 | delete producto.cantidad; | 89 | delete producto.cantidad; |
90 | this.productosCarrito.splice(index, 1); | 90 | this.productosCarrito.splice(index, 1); |
91 | } | 91 | } |
92 | 92 | ||
93 | personalizarPromo(producto: Producto, index) { | 93 | personalizarPromo(producto: Producto, index) { |
94 | 94 | ||
95 | this.productoService.productoAcargar = producto; | 95 | this.productoService.productoAcargar = producto; |
96 | this.productoService.esPromoPersonalizada = true; | 96 | this.productoService.esPromoPersonalizada = true; |
97 | this.deleteProducto(producto, index); | 97 | this.deleteProducto(producto, index); |
98 | this.router.navigate(['inicio']); | 98 | this.router.navigate(['inicio']); |
99 | } | 99 | } |
100 | 100 | ||
101 | } | 101 | } |
102 | 102 |
src/app/services/cliente.service.ts
1 | import { Injectable } from '@angular/core'; | 1 | import { Injectable } from '@angular/core'; |
2 | import { HttpClient } from '@angular/common/http'; | 2 | import { HttpClient } from '@angular/common/http'; |
3 | import { appSettings } from "src/etc/AppSettings"; | 3 | import { APP_SETTINGS } from "src/etc/AppSettings"; |
4 | 4 | ||
5 | @Injectable({ | 5 | @Injectable({ |
6 | providedIn: 'root' | 6 | providedIn: 'root' |
7 | }) | 7 | }) |
8 | export class ClienteService { | 8 | export class ClienteService { |
9 | 9 | ||
10 | private url = appSettings.apiClientes; | 10 | private urlCliente = APP_SETTINGS.apiClientes; |
11 | 11 | ||
12 | constructor(private http: HttpClient) { } | 12 | constructor(private http: HttpClient) { } |
13 | 13 | ||
14 | getClienteById(id: number) { | 14 | getClienteById(id: number) { |
15 | return this.http.get(`${this.url}/get/${id}`); | 15 | return this.http.get(`${this.urlCliente}/get/${id}`); |
16 | } | 16 | } |
17 | } | 17 | } |
18 | 18 |
src/app/services/comanda.service.ts
1 | import { Injectable } from "@angular/core"; | 1 | import { Injectable } from "@angular/core"; |
2 | import { HttpClient } from "@angular/common/http"; | 2 | import { HttpClient } from "@angular/common/http"; |
3 | import { appSettings } from "src/etc/AppSettings"; | 3 | import { APP_SETTINGS } from "src/etc/AppSettings"; |
4 | import { Observable } from "rxjs"; | 4 | import { Observable } from "rxjs"; |
5 | 5 | ||
6 | @Injectable({ | 6 | @Injectable({ |
7 | providedIn: "root" | 7 | providedIn: "root" |
8 | }) | 8 | }) |
9 | export class ComandaService { | 9 | export class ComandaService { |
10 | private apiUrl: string = appSettings.apiUrl; | 10 | private urlAutoservicio: string = APP_SETTINGS.apiAutoservicio; |
11 | 11 | ||
12 | constructor(private http: HttpClient) { } | 12 | constructor(private http: HttpClient) { } |
13 | 13 | ||
14 | getAll(): Observable<any> { | 14 | getAll(): Observable<any> { |
15 | 15 | ||
16 | return this.http.get(`${this.apiUrl}/comandas`); | 16 | return this.http.get(`${this.urlAutoservicio}/comandas`); |
17 | } | 17 | } |
18 | 18 | ||
19 | updateComanda(id: number, estado: number, observacion: string): Observable<any> { | 19 | updateComanda(id: number, estado: number, observacion: string): Observable<any> { |
20 | 20 | ||
21 | return this.http.get(`${this.apiUrl}/comandas/update/${id}/${estado}/${observacion}`); | 21 | return this.http.get(`${this.urlAutoservicio}/comandas/update/${id}/${estado}/${observacion}`); |
22 | } | 22 | } |
23 | 23 | ||
24 | getPendientesEntrega() { | 24 | getPendientesEntrega() { |
25 | return this.http.get(`${this.apiUrl}/comandas/pendientes-entrega`); | 25 | |
26 | return this.http.get(`${this.urlAutoservicio}/comandas/pendientes-entrega`); | ||
26 | } | 27 | } |
27 | } | 28 | } |
28 | 29 |
src/app/services/impresora.service.ts
1 | import { Injectable } from '@angular/core'; | 1 | import { Injectable } from '@angular/core'; |
2 | import { appSettings } from 'src/etc/AppSettings'; | 2 | import { APP_SETTINGS } from 'src/etc/AppSettings'; |
3 | import { HttpClient } from '@angular/common/http'; | 3 | import { HttpClient } from '@angular/common/http'; |
4 | import { Observable } from 'rxjs/internal/Observable'; | 4 | import { Observable } from 'rxjs/internal/Observable'; |
5 | 5 | ||
6 | @Injectable({ | 6 | @Injectable({ |
7 | providedIn: 'root' | 7 | providedIn: 'root' |
8 | }) | 8 | }) |
9 | export class ImpresoraService { | 9 | export class ImpresoraService { |
10 | 10 | ||
11 | private apiAutoservicio = appSettings.apiUrl; | 11 | private urlDeboSuite = APP_SETTINGS.apiDeboSuite; |
12 | 12 | ||
13 | constructor( | 13 | constructor( |
14 | private http: HttpClient, | 14 | private http: HttpClient, |
15 | ) { } | 15 | ) { } |
16 | 16 | ||
17 | getAll(): Observable<any> { | 17 | getAll(): Observable<any> { |
18 | 18 | ||
19 | return this.http.get(`${this.apiAutoservicio}/get/impresoras`); | 19 | return this.http.get(`${this.urlDeboSuite}/get/impresoras`); |
20 | } | 20 | } |
21 | 21 | ||
22 | } | 22 | } |
23 | 23 |
src/app/services/producto.service.ts
1 | import { Injectable } from '@angular/core'; | 1 | import { Injectable } from '@angular/core'; |
2 | import { HttpClient } from '@angular/common/http'; | 2 | import { HttpClient } from '@angular/common/http'; |
3 | import { Observable } from 'rxjs'; | 3 | import { Observable } from 'rxjs'; |
4 | import { appSettings } from 'src/etc/AppSettings'; | 4 | import { APP_SETTINGS } from 'src/etc/AppSettings'; |
5 | import { Producto } from '../wrappers/producto'; | 5 | import { Producto } from '../wrappers/producto'; |
6 | import { ClienteService } from './cliente.service'; | 6 | import { ClienteService } from './cliente.service'; |
7 | 7 | ||
8 | @Injectable({ | 8 | @Injectable({ |
9 | providedIn: 'root' | 9 | providedIn: 'root' |
10 | }) | 10 | }) |
11 | export class ProductoService { | 11 | export class ProductoService { |
12 | 12 | ||
13 | productos: Producto[] = []; | 13 | productos: Producto[] = []; |
14 | productoAcargar: Producto; | 14 | productoAcargar: Producto; |
15 | promoAcargar: Producto; | 15 | promoAcargar: Producto; |
16 | mostrar: string; | 16 | mostrar: string; |
17 | esPromoPersonalizada: boolean = false; | 17 | esPromoPersonalizada: boolean = false; |
18 | 18 | ||
19 | constructor(private http: HttpClient, private clienteService: ClienteService) { } | 19 | constructor(private http: HttpClient, private clienteService: ClienteService) { } |
20 | 20 | ||
21 | getProductoById(id): Observable<any> { | 21 | getProductoById(id): Observable<any> { |
22 | 22 | ||
23 | return this.http.get(`${appSettings.apiUrl}/articulos/${id}`); | 23 | return this.http.get(`${APP_SETTINGS.apiAutoservicio}/articulos/${id}`); |
24 | } | 24 | } |
25 | 25 | ||
26 | getAll(): Observable<any> { | 26 | getAll(): Observable<any> { |
27 | 27 | ||
28 | return this.http.get(`${appSettings.apiUrl}/articulos/`); | 28 | return this.http.get(`${APP_SETTINGS.apiAutoservicio}/articulos/`); |
29 | } | 29 | } |
30 | 30 | ||
31 | getAllWithPaginator(page: number = 1): Observable<any> { | 31 | getAllWithPaginator(page: number = 1): Observable<any> { |
32 | 32 | ||
33 | return this.http.get(`${appSettings.apiUrl}/articulos/${page}`); | 33 | return this.http.get(`${APP_SETTINGS.apiAutoservicio}/articulos/${page}`); |
34 | } | 34 | } |
35 | 35 | ||
36 | setProductos(producto: Producto) { | 36 | setProductos(producto: Producto) { |
37 | 37 | ||
38 | for (let i = 0; i < this.productos.length; i++) { | 38 | for (let i = 0; i < this.productos.length; i++) { |
39 | 39 | ||
40 | if (this.productos[i].id === producto.id) { | 40 | if (this.productos[i].id === producto.id) { |
41 | 41 | ||
42 | if (producto.PRO) { | 42 | if (producto.PRO) { |
43 | if (this.promosIdenticas(this.productos[i], producto)) { | 43 | if (this.promosIdenticas(this.productos[i], producto)) { |
44 | this.productos[i].cantidad++; | 44 | this.productos[i].cantidad++; |
45 | return; | 45 | return; |
46 | } else { | 46 | } else { |
47 | break; | 47 | break; |
48 | } | 48 | } |
49 | } | 49 | } |
50 | this.productos[i].cantidad++; | 50 | this.productos[i].cantidad++; |
51 | return; | 51 | return; |
52 | } | 52 | } |
53 | } | 53 | } |
54 | 54 | ||
55 | this.productos.unshift(producto); | 55 | this.productos.unshift(producto); |
56 | } | 56 | } |
57 | 57 | ||
58 | getPromocionByCodigos(sector, codigo): Observable<any> { | 58 | getPromocionByCodigos(sector, codigo): Observable<any> { |
59 | 59 | ||
60 | var url = `${appSettings.apiUrl}/promociones/by-codigos/${sector}/${codigo}`; | 60 | var url = `${APP_SETTINGS.apiAutoservicio}/promociones/by-codigos/${sector}/${codigo}`; |
61 | // var url = `${appSettings.apiUrl}/promociones/by-codigos/${2}/${7}`; | 61 | // var url = `${appSettings.apiUrl}/promociones/by-codigos/${2}/${7}`; |
62 | return this.http.get(url); | 62 | return this.http.get(url); |
63 | } | 63 | } |
64 | 64 | ||
65 | getPromociones(sector, codigo): Observable<any> { | 65 | getPromociones(sector, codigo): Observable<any> { |
66 | 66 | ||
67 | var url = `${appSettings.apiUrl}/promociones/incluir-articulo/${sector}/${codigo}`; | 67 | var url = `${APP_SETTINGS.apiAutoservicio}/promociones/incluir-articulo/${sector}/${codigo}`; |
68 | // var url = `${appSettings.apiUrl}/promociones/incluir-articulo/${2}/${1306}`; | 68 | // var url = `${appSettings.apiUrl}/promociones/incluir-articulo/${2}/${1306}`; |
69 | return this.http.get(url); | 69 | return this.http.get(url); |
70 | } | 70 | } |
71 | 71 | ||
72 | getPromocionSinonimos(sector, codigo): Observable<any> { | 72 | getPromocionSinonimos(sector, codigo): Observable<any> { |
73 | 73 | ||
74 | var url = `${appSettings.apiUrl}/sinonimos/promo/${sector}/${codigo}`; | 74 | var url = `${APP_SETTINGS.apiAutoservicio}/sinonimos/promo/${sector}/${codigo}`; |
75 | // var url = `${appSettings.apiUrl}/sinonimos/promo/${2}/${7}`; | 75 | // var url = `${appSettings.apiUrl}/sinonimos/promo/${2}/${7}`; |
76 | return this.http.get(url); | 76 | return this.http.get(url); |
77 | } | 77 | } |
78 | 78 | ||
79 | getCategorias() { | 79 | getCategorias() { |
80 | 80 | ||
81 | return this.http.get(`${appSettings.apiUrl}/categorias`); | 81 | return this.http.get(`${APP_SETTINGS.apiAutoservicio}/categorias`); |
82 | } | 82 | } |
83 | 83 | ||
84 | pagar(dataPago: any) { | 84 | pagar(dataPago: any) { |
85 | 85 | ||
86 | return new Observable((observer) => { | 86 | return new Observable((observer) => { |
87 | 87 | ||
88 | this.clienteService.getClienteById(-1).subscribe(cliente => { | 88 | this.clienteService.getClienteById(-1).subscribe(cliente => { |
89 | 89 | ||
90 | this.http.post(`${appSettings.apiUrl}/comprobante/guardar/${dataPago.medioPago}`, { | 90 | let puntoVenta = parseInt(localStorage.getItem('impresoraPVE')); |
91 | this.http.post(`${APP_SETTINGS.apiAutoservicio}/comprobante/guardar/${dataPago.medioPago}`, { | ||
91 | productos: this.productos, | 92 | productos: this.productos, |
92 | cliente: cliente, | 93 | cliente: cliente, |
93 | origen: 'autoservicio', | 94 | origen: 'autoservicio', |
94 | codigoVendedor: 5, | 95 | codigoVendedor: 5, |
95 | puntoVenta: parseInt(localStorage.getItem('impresoraPVE')), | 96 | puntoVenta: dataPago.medioPago === 9 ? -1 * puntoVenta : puntoVenta, |
96 | pedidoAnombreDe: dataPago.pedidoAnombreDe, | 97 | pedidoAnombreDe: dataPago.pedidoAnombreDe, |
97 | }).subscribe((data) => { | 98 | }).subscribe((data) => { |
98 | 99 | ||
99 | observer.next(data); | 100 | observer.next(data); |
100 | observer.complete(); | 101 | observer.complete(); |
101 | }); | 102 | }); |
102 | }); | 103 | }); |
103 | }); | 104 | }); |
104 | } | 105 | } |
105 | 106 | ||
106 | private promosIdenticas(promoEnCarrito: Producto, promo: Producto) { | 107 | private promosIdenticas(promoEnCarrito: Producto, promo: Producto) { |
107 | 108 | ||
108 | var sonIdenticas = true; | 109 | var sonIdenticas = true; |
109 | var productosPromoCarrito = promoEnCarrito.productos; | 110 | var productosPromoCarrito = promoEnCarrito.productos; |
110 | var productosPromoAcargar = promo.productos; | 111 | var productosPromoAcargar = promo.productos; |
111 | 112 | ||
112 | if (productosPromoCarrito.length !== productosPromoAcargar.length) { | 113 | if (productosPromoCarrito.length !== productosPromoAcargar.length) { |
113 | return false; | 114 | return false; |
114 | } | 115 | } |
115 | 116 | ||
116 | for (let i = 0; i < productosPromoCarrito.length; i++) { | 117 | for (let i = 0; i < productosPromoCarrito.length; i++) { |
117 | 118 | ||
118 | if (productosPromoCarrito[i].id !== productosPromoAcargar[i].id) { | 119 | if (productosPromoCarrito[i].id !== productosPromoAcargar[i].id) { |
119 | return false; | 120 | return false; |
120 | } | 121 | } |
121 | } | 122 | } |
122 | 123 | ||
123 | return sonIdenticas; | 124 | return sonIdenticas; |
124 | } | 125 | } |
125 | 126 | ||
126 | } | 127 | } |
127 | 128 |
src/app/services/punto-venta.service.ts
1 | import { Injectable } from '@angular/core'; | 1 | import { Injectable } from '@angular/core'; |
2 | import { Observable } from 'rxjs/internal/Observable'; | 2 | import { Observable } from 'rxjs/internal/Observable'; |
3 | import { appSettings } from 'src/etc/AppSettings'; | 3 | import { APP_SETTINGS } from 'src/etc/AppSettings'; |
4 | import { HttpClient } from '@angular/common/http'; | 4 | import { HttpClient } from '@angular/common/http'; |
5 | 5 | ||
6 | @Injectable({ | 6 | @Injectable({ |
7 | providedIn: 'root' | 7 | providedIn: 'root' |
8 | }) | 8 | }) |
9 | export class PuntoVentaService { | 9 | export class PuntoVentaService { |
10 | 10 | ||
11 | private apiAutoservico = appSettings.apiUrl; | 11 | private apiAutoservico = APP_SETTINGS.apiAutoservicio; |
12 | private apiDeboSuite = APP_SETTINGS.apiDeboSuite; | ||
12 | 13 | ||
13 | constructor( | 14 | constructor( |
14 | private http: HttpClient | 15 | private http: HttpClient |
15 | ) { } | 16 | ) { } |
16 | 17 | ||
17 | getAll(): Observable<any> { | 18 | getAll(): Observable<any> { |
18 | 19 | ||
19 | return this.http.get(`${this.apiAutoservico}/get/puntos-venta`); | 20 | return this.http.get(`${this.apiAutoservico}/get/puntos-venta`); |
20 | } | 21 | } |
21 | 22 | ||
22 | getByID(id: number): Observable<any> { | 23 | getByID(id: number): Observable<any> { |
23 | 24 | ||
24 | return this.http.get(`${this.apiAutoservico}/get/punto-venta/${id}`); | 25 | return this.http.get(`${this.apiAutoservico}/get/punto-venta/${id}`); |
25 | } | 26 | } |
26 | 27 | ||
27 | getVendedor(filter: any = {}): Observable<any> { | 28 | getVendedor(filter: any = {}): Observable<any> { |
28 | 29 | ||
29 | return this.http.get(`${this.apiAutoservico}/get/vendedor/${JSON.stringify(filter)}`); | 30 | return this.http.get(`${this.apiDeboSuite}/get/vendedor/${JSON.stringify(filter)}`); |
30 | } | 31 | } |
31 | 32 | ||
32 | } | 33 | } |
33 | 34 |
src/app/services/tarjetas.service.ts
1 | import { Injectable } from '@angular/core'; | 1 | import { Injectable } from '@angular/core'; |
2 | import { HttpClient } from '@angular/common/http'; | 2 | import { HttpClient } from '@angular/common/http'; |
3 | import { Observable } from 'rxjs'; | 3 | import { Observable } from 'rxjs'; |
4 | import { appSettings } from 'src/etc/AppSettings'; | 4 | import { APP_SETTINGS } from 'src/etc/AppSettings'; |
5 | 5 | ||
6 | @Injectable({ | 6 | @Injectable({ |
7 | providedIn: 'root' | 7 | providedIn: 'root' |
8 | }) | 8 | }) |
9 | export class TarjetasService { | 9 | export class TarjetasService { |
10 | 10 | ||
11 | constructor(private http: HttpClient) { } | 11 | constructor(private http: HttpClient) { } |
12 | 12 | ||
13 | getTarjetas(): Observable<any> { | 13 | getTarjetas(): Observable<any> { |
14 | 14 | ||
15 | return this.http.get(`${appSettings.apiUrl}/tarjetas`); | 15 | return this.http.get(`${APP_SETTINGS.apiAutoservicio}/tarjetas`); |
16 | } | 16 | } |
17 | } | 17 | } |
18 | 18 |
src/etc/AppSettings ejemplo.ts
1 | export const appSettings = { | 1 | export const APP_SETTINGS = { |
2 | // apiUrl: 'http://10.231.45.117:4705/autoservicio', | 2 | // apiAutoservicio: 'http://10.231.45.117:4705/autoservicio', |
3 | // apiDeboSuite: 'http://10.231.45.117:9900', | ||
3 | // apiImagenes: 'http://10.231.45.117:4513/', | 4 | // apiImagenes: 'http://10.231.45.117:4513/', |
4 | // apiClientes: 'http://localhost:1515/clientes' | 5 | // apiClientes: 'http://localhost:1515/clientes' |
5 | }; | 6 | }; |
6 | 7 |