Commit 672dac20d86747d11fe7dd70591bcb0f40e0e609

Authored by Marcelo Puebla
1 parent 0d0fe2b404
Exists in develop

Add

Validacion del maximo de articulos que se puede sumar
Showing 1 changed file with 1 additions and 2 deletions   Show diff stats
src/app/services/articulo/articulo.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 { APP_SETTINGS } from '../../../etc/AppSettings'; 3 import { APP_SETTINGS } from '../../../etc/AppSettings';
4 import { IArticulo } from '../../interfaces/IArticulo'; 4 import { IArticulo } from '../../interfaces/IArticulo';
5 import { ClienteService } from '../cliente/cliente.service'; 5 import { ClienteService } from '../cliente/cliente.service';
6 import { Observable } from 'rxjs'; 6 import { Observable } from 'rxjs';
7 7
8 @Injectable() 8 @Injectable()
9 export class ArticuloService { 9 export class ArticuloService {
10 carrito: IArticulo[] = []; 10 carrito: IArticulo[] = [];
11 articuloAcargar: IArticulo; 11 articuloAcargar: IArticulo;
12 promoAcargar: IArticulo; 12 promoAcargar: IArticulo;
13 mostrar: string; 13 mostrar: string;
14 esPromoPersonalizada = false; 14 esPromoPersonalizada = false;
15 urlDeboSuite = APP_SETTINGS.apiDeboSuite; 15 urlDeboSuite = APP_SETTINGS.apiDeboSuite;
16 medioPago: number; 16 medioPago: number;
17 idComanda: number; 17 idComanda: number;
18 total = 0; 18 total = 0;
19 maxCantidad = 50;
20 19
21 constructor( 20 constructor(
22 private http: HttpClient, 21 private http: HttpClient,
23 private clienteService: ClienteService, 22 private clienteService: ClienteService,
24 ) { } 23 ) { }
25 24
26 getById(id) { 25 getById(id) {
27 return this.http.get(`${this.urlDeboSuite}/articulos/${id}`); 26 return this.http.get(`${this.urlDeboSuite}/articulos/${id}`);
28 } 27 }
29 28
30 getAll() { 29 getAll() {
31 return this.http.get(`${this.urlDeboSuite}/articulos/`); 30 return this.http.get(`${this.urlDeboSuite}/articulos/`);
32 } 31 }
33 32
34 getAllWithPaginator(page: number = 1) { 33 getAllWithPaginator(page: number = 1) {
35 return this.http.get(`${this.urlDeboSuite}/articulos/${page}`); 34 return this.http.get(`${this.urlDeboSuite}/articulos/${page}`);
36 } 35 }
37 36
38 substractCant(articulo: IArticulo) { 37 substractCant(articulo: IArticulo) {
39 if (articulo.cantidad === 1) return; 38 if (articulo.cantidad === 1) return;
40 articulo.cantidad--; 39 articulo.cantidad--;
41 this.calcularTotal(); 40 this.calcularTotal();
42 } 41 }
43 42
44 addCant(articulo: IArticulo) { 43 addCant(articulo: IArticulo) {
45 if (articulo.cantidad >= this.maxCantidad) return; 44 if (articulo.cantidad >= articulo.ExiVta) return;
46 articulo.cantidad++; 45 articulo.cantidad++;
47 this.calcularTotal(); 46 this.calcularTotal();
48 } 47 }
49 48
50 calcularTotal() { 49 calcularTotal() {
51 this.total = 0; 50 this.total = 0;
52 this.carrito.forEach(articulo => { 51 this.carrito.forEach(articulo => {
53 this.total += (articulo.PreVen * articulo.cantidad); 52 this.total += (articulo.PreVen * articulo.cantidad);
54 }); 53 });
55 } 54 }
56 55
57 setArticulo(articulo: IArticulo) { 56 setArticulo(articulo: IArticulo) {
58 articulo.cantidad = 1; 57 articulo.cantidad = 1;
59 for (const articuloCarrito of this.carrito) { 58 for (const articuloCarrito of this.carrito) {
60 if (articuloCarrito.id === articulo.id && !articulo.productos) { 59 if (articuloCarrito.id === articulo.id && !articulo.productos) {
61 articuloCarrito.cantidad++; 60 articuloCarrito.cantidad++;
62 this.calcularTotal(); 61 this.calcularTotal();
63 return; 62 return;
64 } 63 }
65 } 64 }
66 this.setArticulosSinImagen([articulo]); 65 this.setArticulosSinImagen([articulo]);
67 this.carrito.unshift(articulo); 66 this.carrito.unshift(articulo);
68 this.calcularTotal(); 67 this.calcularTotal();
69 } 68 }
70 69
71 deleteArticulo(index: number) { 70 deleteArticulo(index: number) {
72 this.carrito.splice(index, 1); 71 this.carrito.splice(index, 1);
73 this.calcularTotal(); 72 this.calcularTotal();
74 } 73 }
75 74
76 pay(dataPago: any) { 75 pay(dataPago: any) {
77 return new Observable((observer) => { 76 return new Observable((observer) => {
78 this.clienteService.getById(-1) 77 this.clienteService.getById(-1)
79 .subscribe(cliente => { 78 .subscribe(cliente => {
80 this.markArticuloInPromoAsRemoved(); 79 this.markArticuloInPromoAsRemoved();
81 this.http.post(`${this.urlDeboSuite}/comprobante/guardar/${this.medioPago}`, { 80 this.http.post(`${this.urlDeboSuite}/comprobante/guardar/${this.medioPago}`, {
82 productos: this.carrito, 81 productos: this.carrito,
83 cliente, 82 cliente,
84 origen: 'autoservicio', 83 origen: 'autoservicio',
85 codigoVendedor: 5, 84 codigoVendedor: 5,
86 puntoVenta: APP_SETTINGS.puntoVenta, 85 puntoVenta: APP_SETTINGS.puntoVenta,
87 pedidoAnombreDe: dataPago.pedidoAnombreDe, 86 pedidoAnombreDe: dataPago.pedidoAnombreDe,
88 numeroPlanilla: APP_SETTINGS.numeroPlanilla, 87 numeroPlanilla: APP_SETTINGS.numeroPlanilla,
89 pedidoParaLlevar: localStorage.getItem('pedidoParaLlevar'), 88 pedidoParaLlevar: localStorage.getItem('pedidoParaLlevar'),
90 terminal: APP_SETTINGS.terminal, 89 terminal: APP_SETTINGS.terminal,
91 contactLess: true, 90 contactLess: true,
92 }) 91 })
93 .subscribe((data) => { 92 .subscribe((data) => {
94 observer.next(data); 93 observer.next(data);
95 observer.complete(); 94 observer.complete();
96 }, err => { 95 }, err => {
97 observer.error(err); 96 observer.error(err);
98 observer.complete(); 97 observer.complete();
99 }); 98 });
100 }); 99 });
101 }); 100 });
102 } 101 }
103 102
104 cleanShoppingCar() { 103 cleanShoppingCar() {
105 this.articuloAcargar = undefined; 104 this.articuloAcargar = undefined;
106 this.promoAcargar = undefined; 105 this.promoAcargar = undefined;
107 this.carrito = []; 106 this.carrito = [];
108 this.calcularTotal(); 107 this.calcularTotal();
109 } 108 }
110 109
111 setArticulosSinImagen(articulos: IArticulo[]) { 110 setArticulosSinImagen(articulos: IArticulo[]) {
112 articulos.forEach((articulo: IArticulo) => { 111 articulos.forEach((articulo: IArticulo) => {
113 articulo.imagenes = !articulo.imagenes ? [{ imagen: 'noImage.jpg' }] : 112 articulo.imagenes = !articulo.imagenes ? [{ imagen: 'noImage.jpg' }] :
114 !articulo.imagenes.length ? [{ imagen: 'noImage.jpg' }] : articulo.imagenes; 113 !articulo.imagenes.length ? [{ imagen: 'noImage.jpg' }] : articulo.imagenes;
115 }); 114 });
116 } 115 }
117 116
118 markArticuloInPromoAsRemoved() { 117 markArticuloInPromoAsRemoved() {
119 this.carrito.forEach((articuloCarrito: IArticulo) => { 118 this.carrito.forEach((articuloCarrito: IArticulo) => {
120 if (articuloCarrito.PRO) { 119 if (articuloCarrito.PRO) {
121 articuloCarrito.productos.forEach((articulo: IArticulo) => { 120 articuloCarrito.productos.forEach((articulo: IArticulo) => {
122 if (articulo.cantidadAdicionada === 0) { 121 if (articulo.cantidadAdicionada === 0) {
123 articulo.cantidad = 0; 122 articulo.cantidad = 0;
124 articulo.importeValorExtra = 0; 123 articulo.importeValorExtra = 0;
125 } 124 }
126 }); 125 });
127 } 126 }
128 }); 127 });
129 } 128 }
130 129
131 changeArticulo(articuloToChange: IArticulo, articuloData: any) { 130 changeArticulo(articuloToChange: IArticulo, articuloData: any) {
132 articuloToChange.CODA = articuloData.CodArt; 131 articuloToChange.CODA = articuloData.CodArt;
133 articuloToChange.CodArt = articuloData.CodArt; 132 articuloToChange.CodArt = articuloData.CodArt;
134 articuloToChange.SECA = articuloData.CodSec; 133 articuloToChange.SECA = articuloData.CodSec;
135 articuloToChange.CodSec = articuloData.CodSec; 134 articuloToChange.CodSec = articuloData.CodSec;
136 articuloToChange.PreVen = articuloData.PreVen; 135 articuloToChange.PreVen = articuloData.PreVen;
137 articuloToChange.id = articuloData.id; 136 articuloToChange.id = articuloData.id;
138 articuloToChange.DET_LAR = articuloData.DET_LAR; 137 articuloToChange.DET_LAR = articuloData.DET_LAR;
139 articuloToChange.DetArt = articuloData.DetArt; 138 articuloToChange.DetArt = articuloData.DetArt;
140 articuloToChange.MKT_DESC = articuloData.MKT_DESC; 139 articuloToChange.MKT_DESC = articuloData.MKT_DESC;
141 } 140 }
142 } 141 }
143 142