Commit cf95fd9dd51e1021d129890c21be3192c47f91c3

Authored by Marcelo Puebla
1 parent 8260928b08
Exists in master and in 1 other branch validar_pve

cambiado servicio para aceptar el nombre de quien realiza el pedido.

Showing 1 changed file with 5 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 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 return this.http.get(`${appSettings.apiUrl}/categorias`); 81 return this.http.get(`${appSettings.apiUrl}/categorias`);
81 } 82 }
82 83
83 pagar(medioPago: number) { 84 pagar(dataPago: any) {
84 85
85 return new Observable((observer) => { 86 return new Observable((observer) => {
86 87
87 this.clienteService.getClienteById(-1).subscribe(cliente => { 88 this.clienteService.getClienteById(-1).subscribe(cliente => {
88 89
89 this.http.post(`${appSettings.apiUrl}/comprobante/guardar/${medioPago}`, { 90 this.http.post(`${appSettings.apiUrl}/comprobante/guardar/${dataPago.medioPago}`, {
90 productos: this.productos, 91 productos: this.productos,
91 cliente: cliente, 92 cliente: cliente,
92 origen: 'autoservicio' 93 origen: 'autoservicio',
94 pedidoAnombreDe: dataPago.pedidoAnombreDe,
93 }).subscribe((data) => { 95 }).subscribe((data) => {
94 96
95 observer.next(data); 97 observer.next(data);
96 observer.complete(); 98 observer.complete();
97 }); 99 });
98 }); 100 });
99 }); 101 });
100 } 102 }
101 103
102 private promosIdenticas(promoEnCarrito: Producto, promo: Producto) { 104 private promosIdenticas(promoEnCarrito: Producto, promo: Producto) {
103 105
104 var sonIdenticas = true; 106 var sonIdenticas = true;
105 var productosPromoCarrito = promoEnCarrito.productos; 107 var productosPromoCarrito = promoEnCarrito.productos;
106 var productosPromoAcargar = promo.productos; 108 var productosPromoAcargar = promo.productos;
107 109
108 if (productosPromoCarrito.length !== productosPromoAcargar.length) { 110 if (productosPromoCarrito.length !== productosPromoAcargar.length) {
109 return false; 111 return false;
110 } 112 }
111 113
112 for (let i = 0; i < productosPromoCarrito.length; i++) { 114 for (let i = 0; i < productosPromoCarrito.length; i++) {
113 115
114 if (productosPromoCarrito[i].id !== productosPromoAcargar[i].id) { 116 if (productosPromoCarrito[i].id !== productosPromoAcargar[i].id) {
115 return false; 117 return false;
116 } 118 }
117 } 119 }
118 120
119 return sonIdenticas; 121 return sonIdenticas;
120 } 122 }
121 123
122 } 124 }
123 125