Commit 77fef3556a67ab7767342ad62d72bd81576f1ae3

Authored by Marcelo Puebla
1 parent 57ce386197
Exists in master and in 1 other branch validar_pve

pasado dato de vendedor (hardcodeado) y del punto de venta.

Showing 1 changed file with 2 additions and 0 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 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(`${appSettings.apiUrl}/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(`${appSettings.apiUrl}/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(`${appSettings.apiUrl}/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 = `${appSettings.apiUrl}/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 = `${appSettings.apiUrl}/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 = `${appSettings.apiUrl}/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(`${appSettings.apiUrl}/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 this.http.post(`${appSettings.apiUrl}/comprobante/guardar/${dataPago.medioPago}`, {
91 productos: this.productos, 91 productos: this.productos,
92 cliente: cliente, 92 cliente: cliente,
93 origen: 'autoservicio', 93 origen: 'autoservicio',
94 codigoVendedor: 5,
95 puntoVenta: parseInt(localStorage.getItem('impresoraPVE')),
94 pedidoAnombreDe: dataPago.pedidoAnombreDe, 96 pedidoAnombreDe: dataPago.pedidoAnombreDe,
95 }).subscribe((data) => { 97 }).subscribe((data) => {
96 98
97 observer.next(data); 99 observer.next(data);
98 observer.complete(); 100 observer.complete();
99 }); 101 });
100 }); 102 });
101 }); 103 });
102 } 104 }
103 105
104 private promosIdenticas(promoEnCarrito: Producto, promo: Producto) { 106 private promosIdenticas(promoEnCarrito: Producto, promo: Producto) {
105 107
106 var sonIdenticas = true; 108 var sonIdenticas = true;
107 var productosPromoCarrito = promoEnCarrito.productos; 109 var productosPromoCarrito = promoEnCarrito.productos;
108 var productosPromoAcargar = promo.productos; 110 var productosPromoAcargar = promo.productos;
109 111
110 if (productosPromoCarrito.length !== productosPromoAcargar.length) { 112 if (productosPromoCarrito.length !== productosPromoAcargar.length) {
111 return false; 113 return false;
112 } 114 }
113 115
114 for (let i = 0; i < productosPromoCarrito.length; i++) { 116 for (let i = 0; i < productosPromoCarrito.length; i++) {
115 117
116 if (productosPromoCarrito[i].id !== productosPromoAcargar[i].id) { 118 if (productosPromoCarrito[i].id !== productosPromoAcargar[i].id) {
117 return false; 119 return false;
118 } 120 }
119 } 121 }
120 122
121 return sonIdenticas; 123 return sonIdenticas;
122 } 124 }
123 125
124 } 126 }
125 127