Commit 4f59f2e7fc1e14cb9edc76f9ff949d35c0304326
1 parent
aaff6eba2e
Exists in
master
Agregado metodo para traer articulos con paginador.
Showing
1 changed file
with
8 additions
and
3 deletions
Show diff stats
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 | 6 | ||
| 7 | @Injectable({ | 7 | @Injectable({ |
| 8 | providedIn: 'root' | 8 | providedIn: 'root' |
| 9 | }) | 9 | }) |
| 10 | export class ProductoService { | 10 | export class ProductoService { |
| 11 | 11 | ||
| 12 | productos: Producto[] = []; | 12 | productos: Producto[] = []; |
| 13 | productoAcargar: Producto; | 13 | productoAcargar: Producto; |
| 14 | promoAcargar: Producto; | 14 | promoAcargar: Producto; |
| 15 | mostrar: string; | 15 | mostrar: string; |
| 16 | 16 | ||
| 17 | constructor(private http: HttpClient) { } | 17 | constructor(private http: HttpClient) { } |
| 18 | 18 | ||
| 19 | getProductoById(id): Observable<any> { | 19 | getProductoById(id): Observable<any> { |
| 20 | 20 | ||
| 21 | return this.http.get(`${appSettings.apiUrl}/articulos/${id}`); | 21 | return this.http.get(`${appSettings.apiUrl}/articulos/${id}`); |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | getAll(): Observable<any> { | 24 | getAll(page: number = 1): Observable<any> { |
| 25 | 25 | ||
| 26 | return this.http.get(`${appSettings.apiUrl}/articulos`); | 26 | return this.http.get(`${appSettings.apiUrl}/articulos/`); |
| 27 | } | ||
| 28 | |||
| 29 | getAllWithPaginator(page: number = 1): Observable<any> { | ||
| 30 | |||
| 31 | return this.http.get(`${appSettings.apiUrl}/articulos/${page}`); | ||
| 27 | } | 32 | } |
| 28 | 33 | ||
| 29 | setProductos(producto: Producto) { | 34 | setProductos(producto: Producto) { |
| 30 | 35 | ||
| 31 | for (let i = 0; i < this.productos.length; i++) { | 36 | for (let i = 0; i < this.productos.length; i++) { |
| 32 | 37 | ||
| 33 | if (this.productos[i].id === producto.id) { | 38 | if (this.productos[i].id === producto.id) { |
| 34 | 39 | ||
| 35 | if (producto.PRO) { | 40 | if (producto.PRO) { |
| 36 | if (this.promosIdenticas(this.productos[i], producto)) { | 41 | if (this.promosIdenticas(this.productos[i], producto)) { |
| 37 | this.productos[i].cantidad++; | 42 | this.productos[i].cantidad++; |
| 38 | return; | 43 | return; |
| 39 | } else { | 44 | } else { |
| 40 | break; | 45 | break; |
| 41 | } | 46 | } |
| 42 | } | 47 | } |
| 43 | this.productos[i].cantidad++; | 48 | this.productos[i].cantidad++; |
| 44 | return; | 49 | return; |
| 45 | } | 50 | } |
| 46 | } | 51 | } |
| 47 | 52 | ||
| 48 | this.productos.push(producto); | 53 | this.productos.push(producto); |
| 49 | } | 54 | } |
| 50 | 55 | ||
| 51 | getPromocionByCodigos(sector, codigo): Observable<any> { | 56 | getPromocionByCodigos(sector, codigo): Observable<any> { |
| 52 | 57 | ||
| 53 | var url = `${appSettings.apiUrl}/promociones/by-codigos/${sector}/${codigo}`; | 58 | var url = `${appSettings.apiUrl}/promociones/by-codigos/${sector}/${codigo}`; |
| 54 | // var url = `${appSettings.apiUrl}/promociones/by-codigos/${2}/${7}`; | 59 | // var url = `${appSettings.apiUrl}/promociones/by-codigos/${2}/${7}`; |
| 55 | return this.http.get(url); | 60 | return this.http.get(url); |
| 56 | } | 61 | } |
| 57 | 62 | ||
| 58 | getPromociones(sector, codigo): Observable<any> { | 63 | getPromociones(sector, codigo): Observable<any> { |
| 59 | 64 | ||
| 60 | var url = `${appSettings.apiUrl}/promociones/incluir-articulo/${sector}/${codigo}`; | 65 | var url = `${appSettings.apiUrl}/promociones/incluir-articulo/${sector}/${codigo}`; |
| 61 | // var url = `${appSettings.apiUrl}/promociones/incluir-articulo/${2}/${1306}`; | 66 | // var url = `${appSettings.apiUrl}/promociones/incluir-articulo/${2}/${1306}`; |
| 62 | return this.http.get(url); | 67 | return this.http.get(url); |
| 63 | } | 68 | } |
| 64 | 69 | ||
| 65 | getPromocionSinonimos(sector, codigo): Observable<any> { | 70 | getPromocionSinonimos(sector, codigo): Observable<any> { |
| 66 | 71 | ||
| 67 | var url = `${appSettings.apiUrl}/sinonimos/promo/${sector}/${codigo}`; | 72 | var url = `${appSettings.apiUrl}/sinonimos/promo/${sector}/${codigo}`; |
| 68 | // var url = `${appSettings.apiUrl}/sinonimos/promo/${2}/${7}`; | 73 | // var url = `${appSettings.apiUrl}/sinonimos/promo/${2}/${7}`; |
| 69 | return this.http.get(url); | 74 | return this.http.get(url); |
| 70 | } | 75 | } |
| 71 | 76 | ||
| 72 | saveInBase(body): Observable<any> { | 77 | saveInBase(body): Observable<any> { |
| 73 | return this.http.post(`${appSettings.apiUrl}/imagenes/guardar`, body); | 78 | return this.http.post(`${appSettings.apiUrl}/imagenes/guardar`, body); |
| 74 | } | 79 | } |
| 75 | 80 | ||
| 76 | deleteImage(body) : Observable<any>{ | 81 | deleteImage(body): Observable<any> { |
| 77 | return this.http.post(`${appSettings.apiUrl}/imagen/borrar`, body); | 82 | return this.http.post(`${appSettings.apiUrl}/imagen/borrar`, body); |
| 78 | } | 83 | } |
| 79 | 84 | ||
| 80 | getCategorias() { | 85 | getCategorias() { |
| 81 | return this.http.get(`${appSettings.apiUrl}/categorias`); | 86 | return this.http.get(`${appSettings.apiUrl}/categorias`); |
| 82 | } | 87 | } |
| 83 | 88 | ||
| 84 | pagar() { | 89 | pagar() { |
| 85 | return this.http.post(`${appSettings.apiUrl}/comprobante/guardar`, { | 90 | return this.http.post(`${appSettings.apiUrl}/comprobante/guardar`, { |
| 86 | productos: this.productos | 91 | productos: this.productos |
| 87 | }); | 92 | }); |
| 88 | } | 93 | } |
| 89 | 94 | ||
| 90 | private promosIdenticas(promoEnCarrito: Producto, promo: Producto) { | 95 | private promosIdenticas(promoEnCarrito: Producto, promo: Producto) { |
| 91 | 96 | ||
| 92 | var sonIdenticas = true; | 97 | var sonIdenticas = true; |
| 93 | var productosPromoCarrito = promoEnCarrito.productos; | 98 | var productosPromoCarrito = promoEnCarrito.productos; |
| 94 | var productosPromoAcargar = promo.productos; | 99 | var productosPromoAcargar = promo.productos; |
| 95 | 100 | ||
| 96 | if (productosPromoCarrito.length !== productosPromoAcargar.length) { | 101 | if (productosPromoCarrito.length !== productosPromoAcargar.length) { |
| 97 | return false; | 102 | return false; |
| 98 | } | 103 | } |
| 99 | 104 | ||
| 100 | for (let i = 0; i < productosPromoCarrito.length; i++) { | 105 | for (let i = 0; i < productosPromoCarrito.length; i++) { |
| 101 | 106 | ||
| 102 | if (productosPromoCarrito[i].id !== productosPromoAcargar[i].id) { | 107 | if (productosPromoCarrito[i].id !== productosPromoAcargar[i].id) { |
| 103 | return false; | 108 | return false; |
| 104 | } | 109 | } |
| 105 | } | 110 | } |
| 106 | 111 | ||
| 107 | return sonIdenticas; | 112 | return sonIdenticas; |
| 108 | } | 113 | } |
| 109 | 114 | ||
| 110 | } | 115 | } |
| 111 | 116 |