Commit 6b637fa3788f8814f47693f4ad9f7c055cb514b1
Exists in
master
and in
1 other branch
Merge branch 'master' of git.focasoftware.com:angular/autoservicio
# Conflicts: # src/app/services/producto.service.ts
Showing
4 changed files
Show diff stats
src/app/services/cliente.service.spec.ts
File was created | 1 | import { TestBed } from '@angular/core/testing'; | |
2 | |||
3 | import { ClienteService } from './cliente.service'; | ||
4 | |||
5 | describe('ClienteService', () => { | ||
6 | beforeEach(() => TestBed.configureTestingModule({})); | ||
7 | |||
8 | it('should be created', () => { | ||
9 | const service: ClienteService = TestBed.get(ClienteService); | ||
10 | expect(service).toBeTruthy(); | ||
11 | }); | ||
12 | }); | ||
13 |
src/app/services/cliente.service.ts
File was created | 1 | import { Injectable } from '@angular/core'; | |
2 | import { HttpClient } from '@angular/common/http'; | ||
3 | import { appSettings } from "src/etc/AppSettings"; | ||
4 | |||
5 | @Injectable({ | ||
6 | providedIn: 'root' | ||
7 | }) | ||
8 | export class ClienteService { | ||
9 | |||
10 | private url = appSettings.apiClientes; | ||
11 | |||
12 | constructor(private http: HttpClient) { } | ||
13 | |||
14 | getClienteById(id: number) { | ||
15 | return this.http.get(`${this.url}/get/${id}`); | ||
16 | } | ||
17 | } | ||
18 |
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 { appSettings } from 'src/etc/AppSettings'; |
5 | import { Producto } from '../wrappers/producto'; | 5 | import { Producto } from '../wrappers/producto'; |
6 | import { ClienteService } from './cliente.service'; | ||
6 | 7 | ||
7 | @Injectable({ | 8 | @Injectable({ |
8 | providedIn: 'root' | 9 | providedIn: 'root' |
9 | }) | 10 | }) |
10 | export class ProductoService { | 11 | export class ProductoService { |
11 | 12 | ||
12 | productos: Producto[] = []; | 13 | productos: Producto[] = []; |
13 | productoAcargar: Producto; | 14 | productoAcargar: Producto; |
14 | promoAcargar: Producto; | 15 | promoAcargar: Producto; |
15 | mostrar: string; | 16 | mostrar: string; |
16 | esPromoPersonalizada: boolean = false; | 17 | esPromoPersonalizada: boolean = false; |
17 | 18 | ||
18 | constructor(private http: HttpClient) { } | 19 | constructor(private http: HttpClient, private clienteService: ClienteService) { } |
19 | 20 | ||
20 | getProductoById(id): Observable<any> { | 21 | getProductoById(id): Observable<any> { |
21 | 22 | ||
22 | return this.http.get(`${appSettings.apiUrl}/articulos/${id}`); | 23 | return this.http.get(`${appSettings.apiUrl}/articulos/${id}`); |
23 | } | 24 | } |
24 | 25 | ||
25 | getAll(): Observable<any> { | 26 | getAll(): Observable<any> { |
26 | 27 | ||
27 | return this.http.get(`${appSettings.apiUrl}/articulos/`); | 28 | return this.http.get(`${appSettings.apiUrl}/articulos/`); |
28 | } | 29 | } |
29 | 30 | ||
30 | getAllWithPaginator(page: number = 1): Observable<any> { | 31 | getAllWithPaginator(page: number = 1): Observable<any> { |
31 | 32 | ||
32 | return this.http.get(`${appSettings.apiUrl}/articulos/${page}`); | 33 | return this.http.get(`${appSettings.apiUrl}/articulos/${page}`); |
33 | } | 34 | } |
34 | 35 | ||
35 | setProductos(producto: Producto) { | 36 | setProductos(producto: Producto) { |
36 | 37 | ||
37 | for (let i = 0; i < this.productos.length; i++) { | 38 | for (let i = 0; i < this.productos.length; i++) { |
38 | 39 | ||
39 | if (this.productos[i].id === producto.id) { | 40 | if (this.productos[i].id === producto.id) { |
40 | 41 | ||
41 | if (producto.PRO) { | 42 | if (producto.PRO) { |
42 | if (this.promosIdenticas(this.productos[i], producto)) { | 43 | if (this.promosIdenticas(this.productos[i], producto)) { |
43 | this.productos[i].cantidad++; | 44 | this.productos[i].cantidad++; |
44 | return; | 45 | return; |
45 | } else { | 46 | } else { |
46 | break; | 47 | break; |
47 | } | 48 | } |
48 | } | 49 | } |
49 | this.productos[i].cantidad++; | 50 | this.productos[i].cantidad++; |
50 | return; | 51 | return; |
51 | } | 52 | } |
52 | } | 53 | } |
53 | 54 | ||
54 | this.productos.unshift(producto); | 55 | this.productos.unshift(producto); |
55 | } | 56 | } |
56 | 57 | ||
57 | getPromocionByCodigos(sector, codigo): Observable<any> { | 58 | getPromocionByCodigos(sector, codigo): Observable<any> { |
58 | 59 | ||
59 | var url = `${appSettings.apiUrl}/promociones/by-codigos/${sector}/${codigo}`; | 60 | var url = `${appSettings.apiUrl}/promociones/by-codigos/${sector}/${codigo}`; |
60 | // var url = `${appSettings.apiUrl}/promociones/by-codigos/${2}/${7}`; | 61 | // var url = `${appSettings.apiUrl}/promociones/by-codigos/${2}/${7}`; |
61 | return this.http.get(url); | 62 | return this.http.get(url); |
62 | } | 63 | } |
63 | 64 | ||
64 | getPromociones(sector, codigo): Observable<any> { | 65 | getPromociones(sector, codigo): Observable<any> { |
65 | 66 | ||
66 | var url = `${appSettings.apiUrl}/promociones/incluir-articulo/${sector}/${codigo}`; | 67 | var url = `${appSettings.apiUrl}/promociones/incluir-articulo/${sector}/${codigo}`; |
67 | // var url = `${appSettings.apiUrl}/promociones/incluir-articulo/${2}/${1306}`; | 68 | // var url = `${appSettings.apiUrl}/promociones/incluir-articulo/${2}/${1306}`; |
68 | return this.http.get(url); | 69 | return this.http.get(url); |
69 | } | 70 | } |
70 | 71 | ||
71 | getPromocionSinonimos(sector, codigo): Observable<any> { | 72 | getPromocionSinonimos(sector, codigo): Observable<any> { |
72 | 73 | ||
73 | var url = `${appSettings.apiUrl}/sinonimos/promo/${sector}/${codigo}`; | 74 | var url = `${appSettings.apiUrl}/sinonimos/promo/${sector}/${codigo}`; |
74 | // var url = `${appSettings.apiUrl}/sinonimos/promo/${2}/${7}`; | 75 | // var url = `${appSettings.apiUrl}/sinonimos/promo/${2}/${7}`; |
75 | return this.http.get(url); | 76 | return this.http.get(url); |
76 | } | 77 | } |
77 | 78 | ||
78 | getCategorias() { | 79 | getCategorias() { |
79 | return this.http.get(`${appSettings.apiUrl}/categorias`); | 80 | return this.http.get(`${appSettings.apiUrl}/categorias`); |
80 | } | 81 | } |
81 | 82 | ||
82 | getClienteById(id: number = -1): Observable<any> { | 83 | pagar(medioPago: number) { |
83 | 84 | ||
84 | let apiClientes = 'http://10.231.45.220:1515/clientes'; | 85 | return new Observable((observer) => { |
86 | |||
87 | this.clienteService.getClienteById(-1).subscribe(cliente => { | ||
88 | |||
89 | this.http.post(`${appSettings.apiUrl}/comprobante/guardar/${medioPago}`, { | ||
90 | productos: this.productos, | ||
91 | cliente: cliente, | ||
92 | origen: 'autoservicio' | ||
93 | }).subscribe((data) => { | ||
94 | |||
95 | observer.next(data); | ||
96 | observer.complete(); | ||
97 | }); | ||
85 | return this.http.get(`${apiClientes}/get/${id}`); | 98 | }); |
86 | } | 99 | }); |
87 | 100 | } | |
88 | pagar(medioPago: number, cliente: any) { | 101 | |
89 | 102 | private promosIdenticas(promoEnCarrito: Producto, promo: Producto) { | |
90 | return this.http.post(`${appSettings.apiUrl}/comprobante/guardar/${medioPago}`, { | 103 | |
91 | productos: this.productos, | 104 | var sonIdenticas = true; |
92 | cliente: cliente, | 105 | var productosPromoCarrito = promoEnCarrito.productos; |
93 | origen: 'autoservicio', | 106 | var productosPromoAcargar = promo.productos; |
94 | }); | 107 | |
95 | } | 108 | if (productosPromoCarrito.length !== productosPromoAcargar.length) { |
96 | 109 | return false; | |
97 | private promosIdenticas(promoEnCarrito: Producto, promo: Producto) { | 110 | } |
98 | 111 | ||
99 | var sonIdenticas = true; | 112 | for (let i = 0; i < productosPromoCarrito.length; i++) { |
100 | var productosPromoCarrito = promoEnCarrito.productos; | 113 | |
101 | var productosPromoAcargar = promo.productos; | 114 | if (productosPromoCarrito[i].id !== productosPromoAcargar[i].id) { |
102 | 115 | return false; | |
103 | if (productosPromoCarrito.length !== productosPromoAcargar.length) { | 116 | } |
104 | return false; | 117 | } |
105 | } | 118 | |
106 | 119 | return sonIdenticas; | |
107 | for (let i = 0; i < productosPromoCarrito.length; i++) { | 120 | } |
108 | 121 | ||
109 | if (productosPromoCarrito[i].id !== productosPromoAcargar[i].id) { | 122 | } |
110 | return false; | 123 |
src/etc/AppSettings ejemplo.ts
1 | export const appSettings = { | 1 | export const appSettings = { |
2 | // apiUrl: 'http://10.231.45.117:4705/autoservicio', | 2 | // apiUrl: 'http://10.231.45.117:4705/autoservicio', |
3 | // apiImagenes: 'http://10.231.45.117:4513/' | 3 | // apiImagenes: 'http://10.231.45.117:4513/', |
4 | // apiClientes: 'http://localhost:1515/clientes' | ||
4 | }; | 5 | }; |
5 | 6 |