Commit 7cf817c75d449978f59038d39d628f6ab99507cc

Authored by Marcelo Puebla
1 parent ece306d2c2
Exists in develop

Agregado contact less = true

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