articulo.service.ts
2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { APP_SETTINGS } from '../../../etc/AppSettings';
import { IArticulo } from '../../interfaces/IArticulo';
import { ClienteService } from '../cliente/cliente.service';
import { Observable } from 'rxjs';
@Injectable()
export class ArticuloService {
carrito: IArticulo[] = [];
articuloAcargar: IArticulo;
promoAcargar: IArticulo;
mostrar: string;
esPromoPersonalizada: boolean = false;
urlDeboSuite = APP_SETTINGS.apiDeboSuite;
constructor(
private http: HttpClient,
private clienteService: ClienteService,
) { }
getById(id) {
return this.http.get(`${this.urlDeboSuite}/articulos/${id}`);
}
getAll() {
return this.http.get(`${this.urlDeboSuite}/articulos/`);
}
getAllWithPaginator(page: number = 1) {
return this.http.get(`${this.urlDeboSuite}/articulos/${page}`);
}
setArticulo(articulo: IArticulo) {
for (let i = 0; i < this.carrito.length; i++) {
if (this.carrito[i].id === articulo.id) {
if (articulo.PRO) break;
this.carrito[i].cantidad++;
return;
}
}
this.carrito.unshift(articulo);
}
pay(dataPago: any) {
return new Observable((observer) => {
this.clienteService.getById(-1)
.subscribe(cliente => {
let puntoVenta = parseInt(localStorage.getItem('impresoraPVE'));
this.markArticuloInPromoAsRemoved();
this.http.post(`${this.urlDeboSuite}/comprobante/guardar/${dataPago.medioPago}`, {
productos: this.carrito,
cliente: cliente,
origen: 'autoservicio',
codigoVendedor: 5,
puntoVenta: dataPago.medioPago === 9 ? -1 * puntoVenta : puntoVenta,
pedidoAnombreDe: dataPago.pedidoAnombreDe,
numeroPlanilla: '11111',
})
.subscribe((data) => {
observer.next(data);
observer.complete();
});
});
});
}
cleanShoppingCar() {
this.articuloAcargar = undefined;
this.promoAcargar = undefined;
this.carrito = [];
}
setArticulosSinImagen(articulos: IArticulo[]) {
articulos.forEach((articulo: IArticulo) => {
articulo.imagenes = !articulo.imagenes ? [{ imagen: 'noImage.jpg' }] :
!articulo.imagenes.length ? [{ imagen: 'noImage.jpg' }] : articulo.imagenes;
});
}
markArticuloInPromoAsRemoved() {
this.carrito.forEach((articulo: IArticulo) => {
if (articulo.PRO) {
articulo.productos.forEach((articulo: IArticulo) => {
if (articulo.cantidadAdicionada === 0) {
articulo.cantidad = 0;
articulo.importeValorExtra = 0;
}
});
}
});
}
}