Commit 8487f9d126a55ff6a5b36f800a085de28e83b377
Exists in
master
and in
1 other branch
Merge branch 'master' into 'master'
Master(efernandez) See merge request !117
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 | pagar(medioPago: string) { | 83 | pagar(medioPago: string) { |
| 83 | return this.http.post(`${appSettings.apiUrl}/comprobante/guardar/${medioPago}`, { | 84 | |
| 84 | productos: this.productos | 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 | }).subscribe((data) => { | ||
| 93 | |||
| 94 | observer.next(data); | ||
| 95 | observer.complete(); | ||
| 96 | }); | ||
| 97 | }); | ||
| 85 | }); | 98 | }); |
| 86 | } | 99 | } |
| 87 | 100 | ||
| 88 | private promosIdenticas(promoEnCarrito: Producto, promo: Producto) { | 101 | private promosIdenticas(promoEnCarrito: Producto, promo: Producto) { |
| 89 | 102 | ||
| 90 | var sonIdenticas = true; | 103 | var sonIdenticas = true; |
| 91 | var productosPromoCarrito = promoEnCarrito.productos; | 104 | var productosPromoCarrito = promoEnCarrito.productos; |
| 92 | var productosPromoAcargar = promo.productos; | 105 | var productosPromoAcargar = promo.productos; |
| 93 | 106 | ||
| 94 | if (productosPromoCarrito.length !== productosPromoAcargar.length) { | 107 | if (productosPromoCarrito.length !== productosPromoAcargar.length) { |
| 95 | return false; | 108 | return false; |
| 96 | } | 109 | } |
| 97 | 110 | ||
| 98 | for (let i = 0; i < productosPromoCarrito.length; i++) { | 111 | for (let i = 0; i < productosPromoCarrito.length; i++) { |
| 99 | 112 | ||
| 100 | if (productosPromoCarrito[i].id !== productosPromoAcargar[i].id) { | 113 | if (productosPromoCarrito[i].id !== productosPromoAcargar[i].id) { |
| 101 | return false; | 114 | return false; |
| 102 | } | 115 | } |
| 103 | } | 116 | } |
| 104 | 117 | ||
| 105 | return sonIdenticas; | 118 | return sonIdenticas; |
| 106 | } | 119 | } |
| 107 | 120 | ||
| 108 | } | 121 | } |
| 109 | 122 |
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 |